help, error message: Subscripted assignment dimension mismatch.
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Jan
on 3 Jul 2017
Edited: Jan
on 3 Jul 2017
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.
0 Comments
More Answers (1)
angel lerma
on 4 Jul 2017
1 Comment
Szillat
on 21 Dec 2017
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
See Also
Categories
Find more on Desktop in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!