use of for and if

3 views (last 30 days)
maite
maite on 14 Nov 2011
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!!

Answers (2)

Laura Proctor
Laura Proctor on 14 Nov 2011
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 on 14 Nov 2011
idx = find(t >= DT, 1);
plot( t(1:idx), r1(1:idx), 'r', t(idx:end), r2(idx:end), 'g')

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!