Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Mostrar comentarios más antiguos
for i=1:(Num_Ele+Num_Res);
for j=1:(Num_Ele+Num_Res);
for k=1:length(conn);
ind1=conn(k,1);
ind2=conn(k,2);
F(i)=xy(ind2,:)-xy(ind1,:);
A(i,j)= acos(dot(F(k,:),[1,0])/norm(F(k,:)));
end
end
end
Respuestas (2)
You're trying to put x items in y spaces. For example, in the lines below I'm trying to put 3 numbers in 1 space.
x = [10,11,12,13,14];
x(1) = [7,8,9]; % Error!
Here's another example where I try to put 3 items in two spaces.
x = {'d' 'e' 'f' 'g' 'h'};
x(1:2) = {'a','b','c'}; % Error!
One more example with a matrix. Here I try to replace the first row [1,2,3] with [1,2,3,4]
x = [1 2 3;
4 5 6;
7 8 9];
x(1,:) = [1 2 3 4]; % Error!
In your case, if F and A are vectors or matrices then you can only store one value (a scalar) in F(i) and one value in A(i,j). Without knowing what your variable are, I can only guess that this line below produces a vector.
xy(ind2,:)-xy(ind1,:);
So you might be trying to store >1 value in F(i). The same is probably true to A(i,j).
If F and A are cell arrays, then you can store a vector or matrix (and more) into a single element F{i}
So, you need to look at the values you are attempting to store in F(i) and A(i,j) to determine if they are scalars or not.
Luca Parziale
el 12 de Jun. de 2022
I have the same error message :
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
But for this code :
for i = 1:numImages
img = readimage(trainingSet,i);
img = im2gray(img);
% Apply pre-processing steps
img = imbinarize(img);
trainingFeatures(i, :) = extractHOGFeatures(img,'CellSize',cellSize); % cellSize = [4 4];
end
I can make 1030 itéreations and then I get the error message on this line :
trainingFeatures(i, :) = extractHOGFeatures(img,'CellSize',cellSize); % cellSize = [4 4];
The code is this one (from de matlab documentation) :
https://ch.mathworks.com/help/vision/ug/digit-classification-using-hog-features.html
It's exactly the same but with my own dataset of 30x30 images. And I have 5832 images 30x30 in my Dataset.
When I run the code from the link abow (matlab documentation code) it works well but with my dataset it doesn't work and I don't know why ? Could someone give an hint or something to help me please ?
2 comentarios
Walter Roberson
el 12 de Jun. de 2022
I predict that one of the images is not exactly the same size as the others. You should
dbstop if error
and check size(img)
Luca Parziale
el 13 de Jun. de 2022
Thank you. Indeed, I hade one image over 5832 that was 30x26 instead of 30x30 !
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!