% Get a list of all txt files in the current folder, or subfolders of it.

fds = fileDatastore('*.png', 'ReadFcn', @importdata)

fullFileNames = fds.Files
fullFileNames = natsort(fullFileNames)

numFiles = length(fullFileNames)

% Loop over all files reading them in and plotting them.

for k = 1 : numFiles

    fprintf('Now reading file %s\n', fullFileNames{k});
    I = imread (fullFileNames{k});
    %BW = imbinarize (I,0.8);
    
    BW = rgb2gray(I); 
    BW = BW > 150; 
    
    baseFileName = sprintf('Image #%d.jpg', k);
fullFileName = fullfile('C:\Users\Calamity\klara\DP\mereni3\listy\orto_lidar_listy\png\pngvyber\bw\', baseFileName);
imwrite (BW,fullFileName);
    

    % Now have code to read in the data using whatever function you want.

    % Now put code to plot the data or process it however you want...

end