Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Stephen23
Stephen23 el 2 de Mzo. de 2018
Editada: Stephen23 el 2 de Mzo. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 2 de Mzo. de 2018
Editada: Stephen23 el 2 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by