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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Image Analyst
Image Analyst am 11 Feb. 2018
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 am 11 Feb. 2018
Oh sorry about that. i just edited my post. I included all the red text.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 11 Feb. 2018
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 Kommentare
Image Analyst
Image Analyst am 11 Feb. 2018
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 am 11 Feb. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by