Error: A(:) = B, the number of elements in A and B must be the same.

1 次查看(过去 30 天)
Hi everyone, I can't seem to understand why this piece of code:
while( empty_cond ~= 0 && myStack.peek()~= goal)
%pop first index from the stack
i = myStack.pop();
%if node at i has not been visited
if ( visited(i) == 0)
%mark it as visited
visited(i) = 1;
neighbors(i) = sense_maze(i, data);
end
I end up getting this error:
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in RUNME (line 55) neighbors(i) = sense_maze(i, data);
I also attached a picture of the workspace.
  2 个评论
Image Analyst
Image Analyst 2018-2-11
How are we to know which line threw that error? You forgot to include the complete error, which includes the line number and line of code. Please include ALL THE RED TEXT.
Ammar Babikir
Ammar Babikir 2018-2-11
Oh sorry about that. i just edited my post. I included all the red text.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2018-2-11
Two problems. First, sense_maze does not show up in your workspace so the code does not know about it at that point. Secondly data is a structure, not an integer starting from 1. So you need to get the integer from the structure.
  3 个评论
Image Analyst
Image Analyst 2018-2-11
OK, if sense_maze is a function in a separate m-file on the search path, then that is okay. However the error message is acting like sense_maze is an array. Please attach that m-file so I can see what kind of input is expected for its second argument.
data is a structure, not a number - this is what the error message is telling you. So it has fields, like a, b, and myNumber or whatever. Save data to an mat file and attach that also.
Ammar Babikir
Ammar Babikir 2018-2-11
I was able to figure it out. There was an issue with my indexing of neighbors and once I fixed that, my code worked fine.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by