use of for and if
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Laura Proctor
le 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;
0 commentaires
Walter Roberson
le 14 Nov 2011
idx = find(t >= DT, 1);
plot( t(1:idx), r1(1:idx), 'r', t(idx:end), r2(idx:end), 'g')
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!