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

1 回表示 (過去 30 日間)
Canberk Suat Gurel
Canberk Suat Gurel 2018 年 3 月 2 日
編集済み: Stephen23 2018 年 3 月 2 日
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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by