Filter löschen
Filter löschen

Input-Looping Matrix Dimensions Must Agree

2 Ansichten (letzte 30 Tage)
Alvi Syahrin
Alvi Syahrin am 21 Mai 2013
Kommentiert: AS am 15 Sep. 2020
I got this error in very early morning:
Error using - Matrix dimensions must agree.
Error in DistMatrix3 (line 23)
d=sqrt((I-L').^2+(J-M').^2+(K-N').^2);
Error in coba (line 20)
d=DistMatrix3(cobat,c); % calculate the distance
And here is the code of mine: load cobat.txt
k=input('Enter a number: ');
[maxRow, maxCol]=size(cobat);
for i=1:k
for j=1:maxCol
c=input('Enter a number: '); % sequential initialization
end
end
temp=zeros(maxRow,1); % initialize as zero vector
u=0;
while 1,
d=DistMatrix3(cobat,c); % calculate the distance
[z,g]=min(d,[],2); % set the matrix g group
if g==temp, % if the iteration doesn't change anymore
break; % stop the iteration
else
temp=g; % copy the matrix to the temporary variable
end
**for i=1:k
f=find(g==i);
if f % calculate the new centroid
c(i,:)=mean(cobat(find(g==i),:),1);**
end
end
end
y=[cobat,g]
I think the error isn't because the DistMatrix3 itself. It is caused by 'c' inputs. the looping-input. And I guess these lines that should be fixed since it doesn't contain 'j' variables:
for i=1:k
f=find(g==i);
if f % calculate the new centroid
c(i,:)=mean(cobat(find(g==i),:),1);
end
I'm stuck how I should fix it. Can you guys tell me what should I do to solve this this? Your help will be much appreciated.
Thank you.
  1 Kommentar
AS
AS am 15 Sep. 2020
I am using this code but not understood about number of iteration i.e how many iteration are there in the code

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by