4次元配列のforの一つの要素がうまく動きません

조회 수: 4 (최근 30일)
takmakome
takmakome 2022년 6월 28일
댓글: takmakome 2022년 6월 29일
imds = imageDatastore('機械学習500',"IncludeSubfolders",true,"LabelSource","foldernames");
[xtrain,xval] = splitEachLabel(imds,0.5,"randomized");
xtrainimg = augmentedImageDatastore([128 128 1],xtrain,"ColorPreprocessing","gray2rgb");
xvalimg = augmentedImageDatastore([128 128 1],xval,"ColorPreprocessing","gray2rgb");
T = imshow(readimage(imds,1))
Dt= zeros(128,128,1,2050);
Dv = zeros(128,128,1,2050);
for i=1:numel(xtrainimg.Files)
ytraining = xtrain.Labels(i)
yval = xval.Labels(i)
I = imread (xtrainimg.Files{i});
Dt(:,:,:,i) = I
II = imread (xvalimg.Files{i});
Dv(:,:,:,i) = II
end
4個目の画像の数が正しく数えられていなくずっと同じ要素をループしており困っております。
ご教授お願いします。
  댓글 수: 2
Atsushi Ueno
Atsushi Ueno 2022년 6월 28일
for文を回してDt=...やDv=...が繰り返し表示されるのであれば、間違いなくfor文は回っています。numel関数の出力はスカラなので、for文内が何度も繰り返し実行されているのにイテレータiの値が増加しない事も考え難いです。
Dt(:,:,:,1)を変更したときも、Dt(:,:,:,2)を変更した時もDt=...の表示はDt(:,:,:,1)から順に全て表示されるのでスクロールで流れて行ってしまって「ずっと同じ要素をループしている」という誤認識を生んでいるんだと思います。
for文の実行後にDt(:,:,:,3)やDt(:,:,:,4)を表示させれば納得頂けると思います。
takmakome
takmakome 2022년 6월 29일
ありがとうございます。おっしゃる通りうまくできてました、ありがとうございます。

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!