How to use a for loop to generate function inputs

조회 수: 1 (최근 30일)
pldr-bny
pldr-bny 2019년 2월 23일
답변: Geoff Hayes 2019년 2월 23일
I am trying to create an image set from a folder containing 81 subfolders. With three subfolders, '01', '02', '03', this is trivial using the code below:
imgSets = img[imageSet(fullfile(rootfolder,'01')),imageSet(fullfile(rootfolder,'02')), imageSet(fullfile(rootfolder,'03'))];
However, I do not want to specify these paths manually in the 81 folder case. I was able to use a for loop to generate the correct string, but that was very hacky and clearly not best practice. Could anyone help with a function/for loop to achieve this or point me in the right direction for a better solution?
Thank you in advance.

답변 (1개)

Geoff Hayes
Geoff Hayes 2019년 2월 23일
pldr-bny - you could try something like
numberOfImageSets = 81;
imgSets = cell(numberOfImageSets,1);
for k = 1:numberOfImageSets
imgSets{k, 1} = imageSet(fullfile(rootfolder,sprintf('%02d',k)));
end
That might not be exactly what you want...I'm not sure (don't understand) the usage behind the
imgSets = img[....

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by