Output names for splitEachLabel() in a for loop

2 次查看(过去 30 天)
Hello,
I have an imageDataStore (called "imds" with two unique labels. I am wanting to split the imds multiple times, and would like to keep track of the output. Right now I have:
for i=1:5
trname=strcat("trainImgs",string(i));
tstname=strcat("testImgs",string(i));
[trname,tstname]=splitEachLabel(imds,0.8,'randomized');
end
But this just ends up creating two new imageDataStores trname and tstname from the final loop. I am understanding that this is happening because the output of splitEachLabel is assigning values to trname and tstname, and not the characters I assigned them I intended. But I am struggling to fix this. For this example, I am trying to end up with 10 new imageDataStores, trainImgs1, trainImgs2,...,testImgs1, testImgs2,...,testImgs5.
Any advice?
Thank you

采纳的回答

Stephen23
Stephen23 2022-4-6
编辑:Stephen23 2022-4-6
"For this example, I am trying to end up with 10 new imageDataStores, trainImgs1, trainImgs2,...,testImgs1, testImgs2,...,testImgs5."
Do NOT do that (unless you want to force yourself into writing slow, complex, inefficient code):
"Any advice?"
Use basic, simple, neat, and very efficient indexing, just like MATLAB is designed for. For example, using cell arrays:
N = 5;
trainImgs = cell(1,N);
testImgs = cell(1,N);
for k = 1:N
[trname{k},tstname{k}] = splitEachLabel(imds,0.8,'randomized');
end
Very basic MATLAB concepts, such as how to use indexing, are explained in these tutorials:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by