How to reduce matrix size conditionally?
古いコメントを表示
Hi everyone,
My dataset consists of 194 rows and 5 column. in each row either a non-zero value or NaN. I require to pick the non-zero value (only one). There may be more than one non-zero values but all are same, so i need only one. As a resul the size of output matrix will be 194 by 1.
Thansk.

採用された回答
その他の回答 (2 件)
Simon Chan
2022 年 3 月 17 日
Try this:
mean(N_total,2,'omitnan')
Davide Masiello
2022 年 3 月 17 日
編集済み: Davide Masiello
2022 年 3 月 17 日
You could use the max function. See below
% here I reproduce your type of matrix
A = rand(194,1);
A = [A,A,A,A,A];
A(logical(randi([0,1],size(A)))) = nan
% Here I perform the required task
A = max(A,[],2)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!