フィルターのクリア

Using a signal to create a variable

1 回表示 (過去 30 日間)
Anders
Anders 2013 年 3 月 19 日
Hi!
I have three variables, for example;
A = (-1 1 0.5 0.2 -0.7)
B = (1.05 1.05 1.05 1.05 1.03)
C = (0.99 1.01 0.76 1.89 1.23)
And I want to use A as a signal for which values from B and C to create variable D. So that D = B if A<0 and D = C if A>0.
I would then get
D= (1.05 1.01 0.76 1.89 1.03)
I have tried to ask a few questions about how to code this before, but I guess I haven't been specific enough because I haven't gotten it to work. But I haven't been able to work it out on my own with the Help function. So I will give it another go. Any help woul be greatly appreciated!

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 19 日
A = [-1 1 0.5 0.2 -0.7]
B = [1.05 1.05 1.05 1.05 1.03]
C = [0.99 1.01 0.76 1.89 1.23]
D=C
idx=A<0
D(idx)=B(idx)

Image Analyst
Image Analyst 2013 年 3 月 19 日
% Setup:
A = [-1 1 0.5 0.2 -0.7];
B = [1.05 1.05 1.05 1.05 1.03];
C = [0.99 1.01 0.76 1.89 1.23];
% D = B if A<0 and D = C if A>0.
% Answer: D= [1.05 1.01 0.76 1.89 1.03]
% How to do it:
useB = A<0;
D=C; % Initialize
D(useB) = B(useB)

カテゴリ

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