Indexing through an array

3 ビュー (過去 30 日間)
Elizabeth Scharre
Elizabeth Scharre 2021 年 3 月 3 日
コメント済み: James Tursa 2021 年 3 月 3 日
Suppose I have this
B = [1 4 7 10; 2 5 8 11;3 6 9 12]
1 4 7 10
2 5 8 11
3 6 9 12
And I want to check through each column for a value of 2. How would I do this?
  1 件のコメント
James Tursa
James Tursa 2021 年 3 月 3 日
What do you want as a result? A logical array indicating which columns have a 2 in them? An outline for a for-loop that checks for a 2 in a column? Or ...?

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 3 月 3 日
B = [1 4 7 10; 2 5 8 11;3 6 9 12]
B = 3×4
1 4 7 10 2 5 8 11 3 6 9 12
any(B==2,1)
ans = 1x4 logical array
1 0 0 0

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by