use of for and if

2 次查看(过去 30 天)
maite
maite 2011-11-14
hi everybody
I have these two equations
r1=((Imax-Imin)*t)/DT+Imin;
r2=((Imin-Imax)*t)/(T*(1-D))+Imax;
and I also have the following time array
N=200;
h=T/N;
t=[0:h:T-h];
my question is how can I drow those two equations r1 from t=0...DT and r2 from t=DT...T
DT and T are known variables for me I just want to know how to write the function
thank you!!

回答(2 个)

Laura Proctor
Laura Proctor 2011-11-14
If all values are scalars and t is the only vector, you can just leave the equations as they are and MATLAB will create output vectors for r1 & r2.
For example:
N = 200;
h = T/N;
t = 0:h:T-h
r1=((Imax-Imin)*t(t<=DT)/DT+Imin;
r2=((Imin-Imax)*t(t>=DT & t<T)/(T*(1-D))+Imax;

Walter Roberson
Walter Roberson 2011-11-14
idx = find(t >= DT, 1);
plot( t(1:idx), r1(1:idx), 'r', t(idx:end), r2(idx:end), 'g')

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by