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

3 views (last 30 days)
takmakome
takmakome on 28 Jun 2022
Commented: takmakome on 29 Jun 2022
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 Comments
Atsushi Ueno
Atsushi Ueno on 28 Jun 2022
for文を回してDt=...やDv=...が繰り返し表示されるのであれば、間違いなくfor文は回っています。numel関数の出力はスカラなので、for文内が何度も繰り返し実行されているのにイテレータiの値が増加しない事も考え難いです。
Dt(:,:,:,1)を変更したときも、Dt(:,:,:,2)を変更した時もDt=...の表示はDt(:,:,:,1)から順に全て表示されるのでスクロールで流れて行ってしまって「ずっと同じ要素をループしている」という誤認識を生んでいるんだと思います。
for文の実行後にDt(:,:,:,3)やDt(:,:,:,4)を表示させれば納得頂けると思います。
takmakome
takmakome on 29 Jun 2022
ありがとうございます。おっしゃる通りうまくできてました、ありがとうございます。

Sign in to comment.

Answers (0)

Categories

Find more on Matrix Indexing in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!