Is there a function/command call that does 2-d logical

Given for example a = rand(3,3) I want to keep only those entries in a that are greater than say 0.5. How to do this?
I've tried a(a>0.5), but it only gave the values as a vector, not the values situated on where they WERE in a.

回答 (2 件)

Stephen23
Stephen23 2018 年 11 月 13 日
編集済み: Stephen23 2018 年 11 月 13 日

1 投票

Either you can get a vector of only the values that you want (like you were getting), or you can have a matrix by replacing the unwanted values with some value/s of your choice, e.g.:
a = rand(3,3)
a(a<=0.5) = NaN
It is not possible to have a matrix with "holes" in it. Every element of your matrix must contain a value.
madhan ravi
madhan ravi 2018 年 11 月 13 日
編集済み: madhan ravi 2018 年 11 月 13 日

0 投票

a = rand(3)
logicals=a>0.5 %tells where they are located in matrix
values=a(logicals)

カテゴリ

タグ

質問済み:

2018 年 11 月 13 日

編集済み:

2018 年 11 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by