Borrar filtros
Borrar filtros

Using a signal to create a variable

1 visualización (últimos 30 días)
Anders
Anders el 19 de Mzo. de 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!

Respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 19 de Mzo. de 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 el 19 de Mzo. de 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)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by