Input-Looping Matrix Dimensions Must Agree

2 次查看(过去 30 天)
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 个评论
AS
AS 2020-9-15
I am using this code but not understood about number of iteration i.e how many iteration are there in the code

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by