help, error message: Subscripted assignment dimension mismatch.

2 Ansichten (letzte 30 Tage)
angel lerma
angel lerma am 3 Jul. 2017
Kommentiert: Szillat am 21 Dez. 2017
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

Akzeptierte Antwort

Jan
Jan am 3 Jul. 2017
Bearbeitet: Jan am 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.

Weitere Antworten (1)

angel lerma
angel lerma am 4 Jul. 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 Kommentar
Szillat
Szillat am 21 Dez. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Desktop finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by