tmp_1(tmp_2 > 0) What does this command mean in Matlab?

7 ビュー (過去 30 日間)
Bidisha Das
Bidisha Das 2018 年 7 月 20 日
回答済み: Image Analyst 2018 年 7 月 27 日
I have been given a set of matlab codes presently and asked to write them in some other language. But I cannot figure out what this statement means in matlab. To provide context, tmp_1 and tmp_2 are 2 local variables.
Thanks in advance!

回答 (2 件)

Adam
Adam 2018 年 7 月 20 日
tmp_2 > 0
is a logical result of the same size as tmp_2 which is true where tmp_2 is greater than 0 and false otherwise.
tmp_1(tmp_2 > 0)
uses this as a mask into tmp_1 which must be the same size and returns only those elements of tmp_1 for which tmp_2 is greater than 0.

Image Analyst
Image Analyst 2018 年 7 月 27 日
In another non-vectorized language, try a for loop, something like
for k = 1 : length(tmp_2)
if tmp_2(k) > 0
tmp_1(k) = whatever....
end
end
Adapt slightly for the specific language you're using.

カテゴリ

Help Center および File ExchangeLogical (Boolean) Operations についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by