Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Stephen23
Stephen23 le 2 Mar 2018
Modifié(e) : Stephen23 le 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.

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 2 Mar 2018
Modifié(e) : Stephen23 le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by