Azzera filtri
Azzera filtri

Output names for splitEachLabel() in a for loop

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Stephen23
Stephen23 il 6 Apr 2022
Modificato: Stephen23 il 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:

Più risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by