Sorting Struct elements in Numerical order
Show older comments
I have a program which takes some pictures in a struct and performs some pixel counting in each of the pictures. After running the program when I see the struct, the elements are not arranged in the way I want them to be. Here is the code-
img_folder = ('C:\Users\mm\work\blackpixelcount');
filenames = dir(fullfile(img_folder,'*.JPG'));
Total_image = numel(filenames);
for i= 1:Total_image
f = fullfile(img_folder,filenames(i).name);
im= imread(f);
bw= imbinarize(im);
out=nnz(~bw);
get(i)=out;
end
after running the code I see the struct and its sorted as given below-

Now I want the elements to be sorted in numerical ascending order (1,2,3.....9,10,11,12..).
I might be makigs some mistakes there, since I am biggener in matlab. Help will be really appreciated.
1 Comment
Stephen23
on 4 May 2021
S = dir(..);
S = natsortfiles(S);
Accepted Answer
More Answers (1)
Md Farhad Mokter
on 6 Jun 2019
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!