필터 지우기
필터 지우기

Output names for splitEachLabel() in a for loop

조회 수: 2 (최근 30일)
Reid Demass
Reid Demass 2022년 4월 5일
댓글: Reid Demass 2022년 4월 6일
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