Number of elements must be the same??

2 ビュー (過去 30 日間)
Kevin
Kevin 2014 年 7 月 9 日
コメント済み: the cyclist 2014 年 7 月 9 日
Hi,
When running my Matlab programme, I am storing the desired values at the bottom of a for loop. The loop iterates for increasing values of i. However I am getting the following error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in BEM (line 95)
store_Phi(i)=Phi;
Can anybody please help me with this as I am not sure what this means?
Thanks,
Kevin
  1 件のコメント
the cyclist
the cyclist 2014 年 7 月 9 日
This is impossible to diagnose, given the amount of info you have given. Are you able to boil down your code into a short example that we can run ourselves, and that exhibits the error?
You might also benefit reading this page on debugging.

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

回答 (1 件)

dpb
dpb 2014 年 7 月 9 日
store_Phi(i) is a single value in the array and your result Phi is an array of some dimension. If this is intended, then you must have an addressing expression on the LHS of the assignment that matches in size that of the RHS.
I'll presume Phi is a column vector and you're building a 2D array of those columns...then the assignment would look like--
store_Phi(:,i)=Phi; % store ith column, all rows.
Rearrange the subscripts if row-vector, obviously.
You'll want to have preallocated the result array before the loop, of course.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by