I assigned 2 element vectors to a matrix but something is not working.

조회 수: 1 (최근 30일)
Hello all,
I need to present a 2D (250 by 150) coordinate system using a matrix. So I assigned the coordinates (2-element vectors) to a matrix using the following code:
for i=0:250
for j=150:-1:0
temp = [i,j];
row = 150-j+1;
column = i+1;
Nodes(row, column) = {temp};
end
end
and obtained a 151x251 cell. But then when I try to indexing a particular element of the matrix
[x,y] = Nodes(1,1);
I am receiving the following error:
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
because apparently Nodes(1,1) returns [1x2 double].
How can I solve this issue? Thanks.
I am using MATLAB 2016a.
  댓글 수: 1
Stephen23
Stephen23 2018년 3월 2일
편집: Stephen23 2018년 3월 2일
"because apparently Nodes(1,1) returns [1x2 double]."
It does that because that is exactly how you defined it. MATLAB does not just "apparently" do things: bugs aside it just does what you tell it to do and what it is documented to do.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2018년 3월 2일
편집: Stephen23 2018년 3월 2일
x = Nodes{1,1}(1)
y = Nodes{1,1}(2)
Although you would be better off putting your numeric data into one/two numeric arrays, rather than complicating things with an unnecessary cell array.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by