필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by