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

stacks in matlab

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.

Best Answer

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.
Related Question