Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

1.106 Ansichten (letzte 30 Tage)
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

Antworten (2)

Adam Danz
Adam Danz am 12 Jul. 2018
Bearbeitet: Adam Danz am 22 Mai 2019
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!
These are indexing errors.
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
Luca Parziale am 12 Jun. 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 Kommentare
Walter Roberson
Walter Roberson am 12 Jun. 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)

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by