Binary array error message

1 次查看(过去 30 天)
Juan P. Viera
Juan P. Viera 2012-3-22
Basically I get the following error message:
Number of array dimensions must match for binary array op
The thing I don't understand is that, if I stop in the debugger, just before that line and run that line by writing it in the command window, it gives no problem, but then a hit F10 for the debugger to calculate that line and then I get the error message.
I am trying to simply sum two vectors of 783x1
One of the vectors, though, comes from a function which uses ASSIGNIN to create it. I don't know if that has anything to do with the error I am getting. This vector is of just 1s and 0s, the other one is just a bunch of numbers calculated just lines before.
Again, the thing I don't understand is why can I write the code and get the calculation but the program won't do it by itself.
As aditional info, if I run whos both vectors are the same size and double.
Thanks in advance.
JP

回答(2 个)

Image Analyst
Image Analyst 2012-3-22
Can you do this in the command window when you've stopped there (before you step on the line to cause the error):
size(array1) % Note: no semicolon
size(array2) % Replace array1 and array2 with your actual array names.
Then tell us what it says. That means copy and paste it back here. Then step on the line and copy and paste the red error text back here.

Juan P. Viera
Juan P. Viera 2012-3-22
Thank you so much. Here is what happened:
I didn't check that this vector's name (flow) was already a default array name in matlab, so when usining ASSIGNIN the vector got assigned the default flow array and not my flow vector.
size(flow) returned something with 3 numbers, not 783x1
I fixed it, but what I still don't understand is why would MATLAB show flow as a 783x1 vector in the workspace but use the default flow array when called from the editor.
Weird
Thanks again!
JP
  1 个评论
Geoff
Geoff 2012-3-22
Sounds like a problem with local and global scope. If flow exists in the workspace's namespace, and you call size(flow) from your function's namespace, the inbuilt flow function will be called because your function does not have access to the workspace. In general, I would avoid using assignin() unless absolutely necessary. Where possible, use parameters to pass information into a function and return values to get information out.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Code Execution 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by