Effacer les filtres
Effacer les filtres

Output names for splitEachLabel() in a for loop

2 vues (au cours des 30 derniers jours)
Reid Demass
Reid Demass le 5 Avr 2022
Commenté : Reid Demass le 6 Avr 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

Réponse acceptée

Stephen23
Stephen23 le 6 Avr 2022
Modifié(e) : Stephen23 le 6 Avr 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:

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by