I want the number of rows that have bigger than 0 or 1

2 ビュー (過去 30 日間)
Giannakis Stoukas
Giannakis Stoukas 2015 年 3 月 23 日
コメント済み: per isakson 2015 年 3 月 23 日
For example i have the matrix A=[2 3 1; 4 7 6; 1 9 1; 1 0 1] and i want the overall number of the rows that have bigger than 1 price. To this exammple the number i should get is 3,because the max price of the last row is 1.

採用された回答

per isakson
per isakson 2015 年 3 月 23 日
編集済み: per isakson 2015 年 3 月 23 日
Is this what you look for
length(find(max(A,[],2)>1))
ans =
3
  2 件のコメント
Guillaume
Guillaume 2015 年 3 月 23 日
That's a bit convoluted!
per isakson
per isakson 2015 年 3 月 23 日
Agree!

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

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 3 月 23 日
sum(any(A > 1, 2))
Basically,
  • A > 1 compare the matrix to 1, this returns a matrix of logical
  • any(X, 2) returns a column vector that is true if any of the row element is true, so any(A>1, 2) is a column with 1 for any row that as at least one element >1.
  • sum(X) sums all the ones for the rows that have at least one element greater than 1, so is the number of rows that you want

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by