How to sort filenames that are stored by dir command
list = dir(‘*.bmp’);
%preallocate cell array
img = cell(length(list),1);
f = cell(length(list), 250-100);
for i = 1:length(list)
img{i} = imread(list(i).name);
end
%Loop through each image
for i = 1:length(list)
a=img{i}
b=rgb2gray(a);
imwrite(b,sprintf(‘%d.png’,i))
end
That is the simplified code
Problem is that
"dir" command read files in false order, for example:
file1, file11, file111, file2, file22, file222, file3, file33, file333
in fact it should be
file 1, file 2, file 3, file 11, file 22, file 33, file 111, file 222, file 333
How can sort this order in correct versionlist = dir(‘*.bmp’);
%preallocate cell array
img = cell(length(list),1);
f = cell(length(list), 250-100);
for i = 1:length(list)
img{i} = imread(list(i).name);
end
%Loop through each image
for i = 1:length(list)
a=img{i}
b=rgb2gray(a);
imwrite(b,sprintf(‘%d.png’,i))
end
That is the simplified code
Problem is that
"dir" command read files in false order, for example:
file1, file11, file111, file2, file22, file222, file3, file33, file333
in fact it should be
file 1, file 2, file 3, file 11, file 22, file 33, file 111, file 222, file 333
How can sort this order in correct version list = dir(‘*.bmp’);
%preallocate cell array
img = cell(length(list),1);
f = cell(length(list), 250-100);
for i = 1:length(list)
img{i} = imread(list(i).name);
end
%Loop through each image
for i = 1:length(list)
a=img{i}
b=rgb2gray(a);
imwrite(b,sprintf(‘%d.png’,i))
end
That is the simplified code
Problem is that
"dir" command read files in false order, for example:
file1, file11, file111, file2, file22, file222, file3, file33, file333
in fact it should be
file 1, file 2, file 3, file 11, file 22, file 33, file 111, file 222, file 333
How can sort this order in correct version reading images from folder in correct order, filename sorting, natsortfiles MATLAB Answers — New Questions