Effacer les filtres
Effacer les filtres

Using a signal to create a variable

1 vue (au cours des 30 derniers jours)
Anders
Anders le 19 Mar 2013
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!

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 19 Mar 2013
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 le 19 Mar 2013
% 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)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by