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

1 回表示 (過去 30 日間)
Ammar Babikir
Ammar Babikir 2018 年 2 月 11 日
コメント済み: Ammar Babikir 2018 年 2 月 11 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by