Counting number of elements less than value across 2d matrix
20 ビュー (過去 30 日間)
古いコメントを表示
I have a two-dimensional matrix of numbers size A(720,1440). I'd like to calculate the percent of values in part of the matrix -- i.e., from 401:440 and 1081:1360 -- where values are less than or equal to 5, exclusing NaN values.
In order to accomplish this, I'd like to first count the number of elements for this part of A (401:440,1081:1360) where values are less than 5, but omiting any NaN values.
I'm trying to do this using the sum function like below but I'm striking out. Any suggestions?
sum(A(401:440,1081:1360)<=5)
0 件のコメント
採用された回答
Adam Danz
2024 年 5 月 20 日
編集済み: Adam Danz
2024 年 5 月 20 日
> I'd like to calculate the percent of values in part of the matrix -- i.e., from 401:440 and 1081:1360 -- where values are less than or equal to 5, exclusing NaN values.
A = randi(10,720,1440);
mu = mean(A(401:440,1081:1360)<=5,'all','omitnan')
> I'd like to first count the number of elements for this part of A (401:440,1081:1360) where values are less than 5, but omiting any NaN values.
As you can see above, this step isn't needed. But for completeness,
count = sum(A(401:440,1081:1360)<=5,'all','omitnan')
To verity the mean computed above,
totalNumberOfElements = numel(A(401:440,1081:1360))
myConfirmed = count/totalNumberOfElements
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!