use of for and if
2 次查看(过去 30 天)
显示 更早的评论
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!!
0 个评论
回答(2 个)
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;
0 个评论
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')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!