Multidimensional Array indexing to a single vector

I want to check to see if a portion of each column of my array meets a criteria and if it does give a value of 1 and if it doesn't, 0. So x=B(1:5,:)>10 and if B is a 10X10 array, I would like to have x be a 1X10 column vector of ones or zeros. I know this can be done with a loop, but is there anyway to do it without one?

 採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 21 日

0 投票

You do not indicate how you want to transform the 5 x 10 result of B(1:5,:)>10 into a 1 x 10 vector (incidentally, 1 x 10 is a row vector). Perhaps you want
any(B(1:5,:)>10)
or
all(B(1:5,:)>10)

1 件のコメント

Dash
Dash 2012 年 6 月 21 日
Thanks for those commands and yes you're right I meant a row vector.

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

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2012 年 6 月 21 日

0 投票

sum(B(1:5,:)>10)>0

1 件のコメント

Walter Roberson
Walter Roberson 2012 年 6 月 21 日
This would be equivalent to the any() code.

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

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by