dimension mismatch error in Matlab

Hi everybody,
When i run my program the following error occurs.
"Subscripted assignment dimension mismatch."
I don't know what it means, in particular what it is saying about dimension! i just have some vectors in 1*6 or 3*6.
Looking forward to hearing from you
Best,

2 件のコメント

Javier
Javier 2012 年 9 月 20 日
Possible problems.
Vector multiplication error. M(3x1)*N(2x3).
Define break points in the code to search in what line the error occurs.
Hope it helps
Javier
Respaco
Respaco 2012 年 9 月 20 日
Thanks Javier. Actually Matlab shows in which line it has found this error but i can not understand the mistake. It is such a code : A(i,:)=B(1,:);

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

 採用された回答

Matt Fig
Matt Fig 2012 年 9 月 20 日
編集済み: Matt Fig 2012 年 9 月 20 日

0 投票

With code like this:
A(i,:)=B(1,:); % Assume i is a scalar...
you need to make sure that:
size(B,2)==size(A,2)
For example:
A = zeros(6,3);
B = magic(3);
TF = size(B,2)==size(A,2) % True, so o.k.
ii = 2;
A(ii,:)=B(1,:); % This works, because TF is 1.
but, this doesn't work:
A = zeros(3,6);
B = magic(3);
TF = size(B,2)==size(A,2) % False, so not o.k.
ii = 2;
A(ii,:)=B(1,:); % This doesn't works, because TF is 0.

3 件のコメント

Respaco
Respaco 2012 年 9 月 20 日
Thanks but the number of coloumns for both matrices are the same. Actually when i run my program for 50 to 100 iterations it runs successfully and get me the solution with no error about matrices or sizes but for larger iterations like 1000 the mismatch error occurs. I want to know how it has no error for few iterations? how it really happens?!
thanks
Matt Fig
Matt Fig 2012 年 9 月 20 日
Show the relevant code, because there is something you are leaving out. This works and it goes beyond 1000:
A = zeros(2000,3); % 2000 rows.
B = rand(2000,3);
TF = size(B,2)==size(A,2) % True, so o.k.
for ii = 1:2000,A(ii,:) = B(randi(2000),:);end
Walter Roberson
Walter Roberson 2012 年 9 月 20 日
At the point of error, check to see whether "i" has become a vector.
If it has become a vector, then my crystal ball thinks you might need to read http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by