help, error message: Subscripted assignment dimension mismatch.

2 次查看(过去 30 天)
hi, I am a very new in MatLab, I am working in MatLab R2017a on Win 10, it's a CNN example, this is the code:
% working path
path( path, 'C:\Users\mlerma\Documents\MATLAB\thesis');
cd C:\Users\mlerma\Documents\MATLAB\thesis
%%prepare
% currentFolder = pwd ;
clear ; close all ; clc ;
%%Load image
imsetTrain = imageSet('images','recursive');
%%Display Sampling of Image Data
numClasses = size(imsetTrain,2);
imagesPerClass = 20;
imagesInMontage = cell(imagesPerClass,numClasses);
for i = 1:size(imagesInMontage,2)
imagesInMontage(:,i) = ...
imsetTrain(i).ImageLocation(randi(imsetTrain(i).Count, 1, ...
imagesPerClass));
end
montage({imagesInMontage{:}},'Size',[numClasses,imagesPerClass]);
title('Imagenes de Ejemplo')
%%Prepare the data for Training
% Read all images and store them in a 4D uint8 input array for training,
% with its corresponding class
trainNames = {imsetTrain.Description};
XTrain = zeros(720,480,3,sum([imsetTrain.Count]),'uint8');
TTrain = categorical(discretize((1:sum([imsetTrain.Count]))',...
[0,cumsum([imsetTrain.Count])],'categorical',trainNames));
j = 0;
tic;
for c = 1:length(imsetTrain)
for i = 1:imsetTrain(c).Count
XTrain(:,:,:,i+j) = read(imsetTrain(c),i);
end
j = j + imsetTrain(c).Count;
end
toc;
the error is en line:
XTrain(:,:,:,i+j) = read(imsetTrain(c),i);
the message error is:
"Subscripted assignment dimension mismatch."
someone can help me??
thks in advanced
Angel

采纳的回答

Jan
Jan 2017-7-3
编辑:Jan 2017-7-3
Use the debugger to examine the problem. Type this in the command window:
dbstop if error
Now run your code again until it stops at the error. Now check this:
size(XTrain(:,:,:,i+j))
size(read(imsetTrain(c),i))
Are they equal? If not, the assignment cannot work.
Perhaps you want:
k = imsetTrain(c).Count
XTrain(:,:,:, j:j+k-1) = read(imsetTrain(c),i);
j = j + k;
? Due to the lack of comments the readers (and you in some month) can only guess, what is intented.

更多回答(1 个)

angel lerma
angel lerma 2017-7-4
hello Jan: you are rigth the values were different, so I fix it and these part work fine.
A lot of thaks...... Best regards... Angel
  1 个评论
Szillat
Szillat 2017-12-21
Sorry, but how do you fix it? I put:
j = 0;
tic;
for c = 1:length(imsetTrain)
for i = 1:imsetTrain(c).Count
XTrain(:,:,i+j) = read(imsetTrain(c),i);
end
j = j + imsetTrain(c).Count;
end
toc;
but it doesn't work

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Desktop 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by