Create a list of images from subfolders with specific names using dir , strcat!
9 ビュー (過去 30 日間)
古いコメントを表示
There should be two seperate for-loop but in the first loop it overwright and just I can get the last year images. I also tried fullfile but I got problem with the imread in the second loop because of the path name. I want to create a list of all images with special names as what assgined below among the total number located in diffrent subfolder. But It just gives the last years.
%activity= 'run' or 'dart'
year1 = 1980
year2= 2010
for num= year1:year2
switch activity
case 'Indai'
path = ['C\folder\competition\run','\',num2str(num),'\']; % get images with this name from all subfolders
if strcmp(age,'rd')
ag = 'old';
list_images= dir([datapath 'run_',num2str(d),'*_',country,ag,'.png'])
elseif strcmp(age,'rs') %German
ag = '';
list_images=dir([path 'run_',num2str(d),'*_',country,ag,'.png']);% get images with this name from all subfolders
end
ti = 1;
case 'Africa'
path = ['C\folder\competition\dart','\',num2str(num),'\'];
list_images=dir([datapath 'dart',country,'_',num2str(d),'*.png'])% get images with this name from all subfolders
ti = 2;
end
for i=1:length(images)
filename = strcat(images(i).folder,'/',images(i).name);% Concatenate strings horizontally to create a full path
I= imread(filename);% fo further process of showing image a series
end
0 件のコメント
採用された回答
Guillaume
2019 年 7 月 26 日
Very confusing code and confusing question.
But It just gives the last years.
Well, yes of course, in the loop you overwrite list_images at each step. So when the loop finishes, you're left with just the value you've written last.
You could rewrite your loop as such:
year1 = 1980
year2 = 2010
years = year1:year2;
list_images = cell(size(years));
for yearindex = 1:numel(years)
num = years(yearindex); %num is an extremely poor variable name!
%....
list_images{yearindex} = ...
end
But the whole thing should be rewritten to extract the switch and the if...elseif out of the loop, and using fullfile indeed instead of char vector concatenation. fullfile is always more reliable and if you've got problem (what problem? always state the full text of any error you get), then it's because you've made a mistake, not because it doesn't work.
2 件のコメント
vania todorova
2021 年 7 月 23 日
newbie here. why does it have to be specifically a cell array ? is it something that works with images better? i m mostly a python user and i would just use a list but trying to figure out how to separate image ds into groups of 5 images easiest . thanks!
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!