필터 지우기
필터 지우기

Using a signal to create a variable

조회 수: 3 (최근 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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by