How to create binary vector that can be applyied conditional case

3 ビュー (過去 30 日間)
Jinsu Kim
Jinsu Kim 2018 年 11 月 28 日
編集済み: madhan ravi 2018 年 11 月 28 日
Hi guys,
I have input vector A (6x1), [ 0.4, 0.8, 0.9, 1.0 1.1, 1.4 ] What I want to do is returning to zero if each value exceed one.
>> My idea is create a vector, B'(6x1) like this: [ 1, 1, 1, 0, 0, 0 ] and then calculate by each element.
In that way I can get the answer, C'(6x1) = [ 0.4, 0.8, 0.9, 0, 0, 0 ]
The questions is that is there any way to create binary vector like above?
Thanks in advances:D

採用された回答

madhan ravi
madhan ravi 2018 年 11 月 28 日
編集済み: madhan ravi 2018 年 11 月 28 日
A= [ 0.4, 0.8, 0.9, 1.0 1.1, 1.4 ]
B=A<1;
B=B.'
C=zeros(1,numel(A));
C(B)=A(B)
command window:
A =
0.4000 0.8000 0.9000 1.0000 1.1000 1.4000
B =
1×6 logical array
1 1 1 0 0 0
C =
0.4000 0.8000 0.9000 0 0 0
>>
  2 件のコメント
Jinsu Kim
Jinsu Kim 2018 年 11 月 28 日
Thank you!! I will try it on.
madhan ravi
madhan ravi 2018 年 11 月 28 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by