Number of elements must be the same??
2 views (last 30 days)
Show older comments
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 Comment
the cyclist
on 9 Jul 2014
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?
Answers (1)
dpb
on 9 Jul 2014
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.
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!