フィルターのクリア

how to efficiently update one element in a matrix conditioned on another element

1 回表示 (過去 30 日間)
xueqi
xueqi 2014 年 3 月 16 日
回答済み: the cyclist 2014 年 3 月 16 日
Hi,
Do you know how to do this? I have a matrix M=[2,3,2;-1,2,3]. I would like to check in any row, if there is a number is less than 0. If so, I let the second column of that row is equal to -Inf. So in this case, as M(2,1)<0.So I update M as [2,3,2;-1,-Inf,3].
I understand I probably can write a loop to do so. But the problem is I need to deal with a big matrix other than M here, which is only 2*3. I will like to speed up the process. So I would like to know if there is an more efficient way to do so? Could any one help me about this please?

採用された回答

the cyclist
the cyclist 2014 年 3 月 16 日
M(any(M<0,2),2) = -Inf;

その他の回答 (0 件)

カテゴリ

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