use of for and if

3 visualizaciones (últimos 30 días)
maite
maite el 14 de Nov. de 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!!

Respuestas (2)

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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by