필터 지우기
필터 지우기

Input-Looping Matrix Dimensions Must Agree

조회 수: 2 (최근 30일)
Alvi Syahrin
Alvi Syahrin 2013년 5월 21일
댓글: AS 2020년 9월 15일
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