Trouble pulling out numbers from a matrix into variables

1 回表示 (過去 30 日間)
Steve
Steve 2014 年 5 月 1 日
コメント済み: Star Strider 2014 年 5 月 1 日
So I need to scan a matrix for any "1" in the 6th column and then if that row has a 1 in the 6th column, I need to turn the 2nd column of the same row into an x variable, and the 4th column of the same row into a y variable, so I can plot it later.
From my understanding I need to use the intersect function? I am new to matlab and don't exactly know how to use it, or am I using the wrong function? If someone could show me how to do this I would really appreciate it. Thanks in advance

採用された回答

Star Strider
Star Strider 2014 年 5 月 1 日
編集済み: Star Strider 2014 年 5 月 1 日
I suppose you could use intersect, but a simpler approach will work, especially if your matrix isn’t huge:
M = randi(10, 15, 6) % Create data
x = M(M(:,6)==1,2) % Use logical indexing to get ‘x’ from column 2
y = M(M(:,6)==1,4) % and ‘y’ from column 4
  2 件のコメント
Steve
Steve 2014 年 5 月 1 日
thanks! and good explanation too
Star Strider
Star Strider 2014 年 5 月 1 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by