Input-Looping Matrix Dimensions Must Agree

1 visualización (últimos 30 días)
Alvi Syahrin
Alvi Syahrin el 21 de Mayo de 2013
Comentada: AS el 15 de Sept. de 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 comentario
AS
AS el 15 de Sept. de 2020
I am using this code but not understood about number of iteration i.e how many iteration are there in the code

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by