Minimum value ineach column

7 ビュー (過去 30 日間)
EldaEbrithil
EldaEbrithil 2020 年 8 月 14 日
コメント済み: EldaEbrithil 2020 年 8 月 14 日
Hi all
i want to extract the minimum positive value in each column, i have used this code
for j=1:length(columnA)
a(j)=min(A(A(:,j)>0));
end
but i am not able to solve the problem. A is a matrix
Thank for the help

採用された回答

Matt J
Matt J 2020 年 8 月 14 日
編集済み: Matt J 2020 年 8 月 14 日
We don't know what columnA is in the code that you've shown. It would have to be a vector with the same number of columns as A for the code to work.
Regardless, the complete operation can easily be done without looping:
B=A: B(A<=0)=+inf;
a=min(B,[],1);
  4 件のコメント
Matt J
Matt J 2020 年 8 月 14 日
編集済み: Matt J 2020 年 8 月 14 日
As I said, it doesn't matter. You don't need the loop. But if you were to use a loop, it would be
for j=1:size(A,2)
a(j)=min( A( A(:,j)>0 , j) );
end
EldaEbrithil
EldaEbrithil 2020 年 8 月 14 日
Thank you very much, now it works!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by