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

1 view (last 30 days)
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 Comment
Stephen23
Stephen23 on 2 Mar 2018
Edited: Stephen23 on 2 Mar 2018
"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.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 2 Mar 2018
Edited: Stephen23 on 2 Mar 2018
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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!