Matlab plotting of a trapezoidal cuve
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello.. I want to plot a trapezoidal curve which is attached here. For that I have written following code but while plotting the value of pressure is not coming as a vector it is giving only a vector of only five value.I am not getting where is my fault plz help....
t(1)=0;
pl=.5;
ph=1.5;
f=2;
h=.1;
t1=0.45/f;
t2=t1+(.15/f);
t3=t2+(0.23/f);
t4=t3+(0.17/f);
%t=t1+t2+t3+t4
tau=1/f;
%p=zeros(1,101);
p(1)=0;
pavg=(ph+pl)/2;
pamp=(ph-pl)/2;
for m=1:1:10
if (t(m)>= 0) && (t(m) <= t1)
p(m+1)=pl+(((ph-pl)/t1)*t(m));
elseif(t(m)>= t1) && (t(m) <= t2)
p(m+1)=ph;
elseif(t(m)>= t2) && (t(m) <= t3)
p(m+1)=ph+(((pl-ph)/(t3-t2))*(t(m)-t2));
elseif(t(m)>= t3) && (t(m) <= t4)
p(m+1)=pl;
end
t(m+1)=t(m)+1;
end end

0 commentaires
Réponses (1)
Satyajeet Sasmal
le 15 Déc 2015
Hi Debashish,
I assume that you want to plot (p,t). But p just has 2 elements and that is why it does not allow it to be plotted against "t". You only get 2 values for p because the control inside the for-loop does not execute some of the if-elseif conditions. In fact, it only enters the if-elseif condition block on only 2 occasions and so you get only 2 values for p. Try giving an else condition to the if-elseif block and assign some value to p in such cases. Once "p" and "t" are the same length, you should be able to plot them.
-Satya
0 commentaires
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!