help, error message: Subscripted assignment dimension mismatch.

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Jan
Jan il 3 Lug 2017
Modificato: Jan il 3 Lug 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.

Più risposte (1)

angel lerma
angel lerma il 4 Lug 2017
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 Commento
Szillat
Szillat il 21 Dic 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

Accedi per commentare.

Categorie

Scopri di più su Desktop in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by