I have a folder with 1500 images. I need to process the first 200 images(ie, 1 to 200). I used for loop it. But when i run the code i starts from 1,2,3 ... 100. then instead if going for 101th image, its value changes to 1001 , 1002... and so on.
1 回表示 (過去 30 日間)
古いコメントを表示
start:1
stop:200
for i = start : stop
XX
end
But i need to continue from 101, 102,... after 100. Kindly help me identify the problem.
0 件のコメント
採用された回答
Stephen23
2016 年 2 月 8 日
編集済み: Stephen23
2021 年 4 月 26 日
The easiest solution is to use my FEX submission natsortfiles. It fixes the order of an ASCII sort to take into account any numeric values in the strings. Note that it requires the file natsort to work!
It simply sorts a cell array of filenames into the order you want:
S = dir('*.jpg');
S = natsortfiles(S);
for k = 1:200 % first 200 files
F = S(k).name;
... your code
end
Note that this answer assumes that your files are sequentially numbered without any gaps. If this is not true, then you need to give more information on the filenaming logic.
2 件のコメント
Stephen23
2016 年 2 月 8 日
編集済み: Stephen23
2021 年 4 月 26 日
Here is one way of solving your task using my answer:
P = 'E:\New Folder';
S = dir(fullfile(P,'*.tif'));
S = natsortfiles(S);
for k = 1:200
F = fullfile(P,S(k).name);
I = imread(F);
figure;
imshow(I);
end
Note:
- you will need to download NATSORTFILES.
- I changed the loop variable from i to k, because in MATLAB i is the imaginary unit.
- I used fullfile to create the path strings, which is much more robust than using strcat.
その他の回答 (1 件)
Image Analyst
2016 年 2 月 8 日
2 件のコメント
Image Analyst
2016 年 2 月 9 日
Stephen, you should notice that first link I gave actually talks about your submission as the "Pick of the Week".
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!