필터 지우기
필터 지우기

How to change a parameter during a plot?

조회 수: 6 (최근 30일)
Eliot
Eliot 2014년 3월 16일
편집: Paul 2014년 3월 16일
I would like to plot a function but change a value part way through the plot, specifically in the code below, for values of (x<M) I would like to set R = RL and for values of (x>M) I would like to set R = RR. Any help appreciated. Thanks
x = 0:0.01:2;
M = 1;
R = 2;
LR = 0.25;
RL = (0.5 / LR) * R;
RR = (0.5 / (1 - LR)) * R;
y = exp(-(4* * *R* * .^2*(log(2))*(M - x).^2)/(M.^2));
plot(x,y)
grid on

채택된 답변

Paul
Paul 2014년 3월 16일
x = 0:0.01:2;
M = 1;
R = 2;
LR = 0.25;
RL = (0.5 / LR) * R;
RR = (0.5 / (1 - LR)) * R;
xL = x(x<M);
xR = x(x>=M);
y(x<M) = exp(-(4*RL.^2.*(log(2)).*(M - xL).^2)/(M.^2));
y(x>=M) = exp(-(4*RR.^2.*(log(2)).*(M - xR).^2)/(M.^2));
plot(x,y)
grid on
I also removed all the * in your function, not sure if there are supposed to be constants there or something.

추가 답변 (1개)

Eliot
Eliot 2014년 3월 16일
Thank you very much for taking the time to answer, I understand how it works now, the bit I was missing was splitting the x array.
  댓글 수: 1
Paul
Paul 2014년 3월 16일
편집: Paul 2014년 3월 16일
There's also an easier method. You can make R a vector with the corresponding value for x<M and x>=M:
x = 0:0.01:2;
M = 1;
R = 2;
LR = 0.25;
RL = (0.5 / LR) * R;
RR = (0.5 / (1 - LR)) * R;
Rc(x<M) = RL;
Rc(x>=M) = RR;
y = exp(-(4.*Rc.^2.*(log(2)).*(M - x).^2)/(M.^2));
figure;
plot(x,y)
grid on
It's important to not forget to use the . for the factors involving Rc too.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by