Setting certain array elements to 0

28 ビュー (過去 30 日間)
John Draper
John Draper 2016 年 6 月 29 日
コメント済み: Star Strider 2016 年 6 月 29 日
Hi everyone, this one is probably pretty simple but I can't seem to figure it out.
I have some matrix let's call it A
if true
A = [ 1, 2 ,-2; 0, 2 ,5; -0.5, 2, 1]
Now i want to set all the values between two specific values to zero, for example the values from 0 to 1. I can set all the values below 1 to 0 quite easily by adding:
if true
A(A<1) = 0
But adding a second inequality into this code doesn't seem to work:
if true
A(0<A<1) = 0
Does anyone have any ideas? Thank in advance John.

採用された回答

Star Strider
Star Strider 2016 年 6 月 29 日
You have to separate the individual logical tests:
A((0<A) & (A<1)) = 0
However, since none of your matrix elements meet those criteria, it will be unchanged.
  2 件のコメント
John Draper
John Draper 2016 年 6 月 29 日
Yup, I knew it was simple! Thank you again Star Strider.
Star Strider
Star Strider 2016 年 6 月 29 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by