Filter löschen
Filter löschen

Output names for splitEachLabel() in a for loop

2 Ansichten (letzte 30 Tage)
Reid Demass
Reid Demass am 5 Apr. 2022
Kommentiert: Reid Demass am 6 Apr. 2022
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

Akzeptierte Antwort

Stephen23
Stephen23 am 6 Apr. 2022
Bearbeitet: Stephen23 am 6 Apr. 2022
"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:

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by