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

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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!