"Subscripted assignment dimension mismatch." error matlab

Hi,
I do not know why I have "Subscripted assignment dimension mismatch." error at line u(i,j)=1./sum_d;. Below is my coding:
%update U
for i=1:nc
for j=1:o
sum_d=0;
for k=1:nc
sum_d = sum_d + (distance(c(i,:),x(j,:))/distance(c(k,:),x(j,:)))^(2/(m_exponent-1));
end
u(i,j)=1./sum_d;
end
end
Hope to get the solution soon.Thanks.

 採用された回答

Walter Roberson
Walter Roberson 2014 年 3 月 2 日

0 投票

What size() does distance(c(i,:),x(j,:)) return? If it is not a scalar then you would be doing "/" between two arrays which is possibly not going to return a scalar.

1 件のコメント

Ong Teng
Ong Teng 2014 年 3 月 2 日
Hi, how can I know the size of distance(c(i,:),x(j,:)) return? I am sorry I am just a new beginner of matlab user.

サインインしてコメントする。

その他の回答 (1 件)

Star Strider
Star Strider 2014 年 3 月 2 日

0 投票

I suggest you run this statement separately (it’s now part of your sum_d statement)
(distance(c(i,:),x(j,:))/distance(c(k,:),x(j,:)))^(2/(m_exponent-1));
and check its dimensions. It might be a vector, meaning that sum_d will be a vector.
This line
u(i,j)=1./sum_d;
wants sum_d to be a scalar.

5 件のコメント

Ong Teng
Ong Teng 2014 年 3 月 2 日
Hi,
Sorry, how can i run it separately?
Thanks.
Star Strider
Star Strider 2014 年 3 月 2 日
d = (distance(c(i,:),x(j,:))/distance(c(k,:),x(j,:)))^(2/(m_exponent-1));
Ong Teng
Ong Teng 2014 年 3 月 2 日
編集済み: Ong Teng 2014 年 3 月 2 日
Hi,
Do u means run the code as below? But I still get the same error. Please help me to solve, please.I am just a new beginner using Matlab. Thanks
%update U
for i=1:nc
for j=1:o
sum_d=0;
for k=1:nc
sum_dx=(distance(c(i,:),x(j,:))/distance(c(k,:),x(j,:)))^(2/(m_exponent-1));
sum_d = sum_d + sum_dx;
end
u(i,j)=1./sum_d;
end
end
Ong Teng
Ong Teng 2014 年 3 月 2 日
Hi,
How can I change this line
u(i,j)=1./sum_d;
wants sum_d to be a vector.
Ong Teng
Ong Teng 2014 年 3 月 4 日
Hi,
Can anyone pls help me on this problem please?
Thanks.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFuzzy Logic Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by