plot multiple equations in a for loop

조회 수: 1 (최근 30일)
majid eid
majid eid 2015년 4월 17일
댓글: majid eid 2015년 4월 17일
Hi everyone. I am trying to plot multiple graph in Matlab. it seems that matlab over wrights the values in each loop so when i try to plot it doesn't give any results ....so how can i save the values for every loop to plot them ?? here is the code
tc=40;
te=15;
c1=137.402;
c2=4.60437;
c3=0.061652;
c4=-1.118157;
c5=-.001525;
c6=-.0109119;
c7=-.00040148;
c8=-.00026682;
c9=.000003873;
d1=1.00618;
d2=-.893222;
d3=-.01426;
d4=0.870024;
d5=-.0063397;
d6=.033889;
d7=-.00023875;
d8=-.00014746;
d9=.0000067962;
for ta=[20:5:50];
qe=c1+c2*te+c3*te^2+c4*tc+c5*tc^2+c6*te*tc+c7*te^2*tc+c8*te*tc^2+c9*te^2*tc^2;
p=d1+d2*te+d3*te^2+d4*tc+d5*tc^2+d6*te*tc+d7*te^2*tc+d8*te*tc^2+d9*te^2*tc^2;
a=1;
b=(0.54*10+6)/0.27;
c=10^2+(6*10)/0.27-qe/0.27;
te=(-b+sqrt(b^2-4*a*c))/(2*a);
qc=qe+p;
tc=(qc/9.6)+ta;
ta,qe,p,te,qc,tc,
end
plot(ta,qe,ta,p,ta,te,ta,qc,ta,tc)

채택된 답변

Michael Haderlein
Michael Haderlein 2015년 4월 17일
Please, use the {} Code button above the field you're writing your question to make the post be readable.
Also, you should learn about the array concept of Matlab. Your equations look kind of like scalar products, so most likely you can significantly shorten your code and avoid typos this way.
With respect to your question, in this case it's easier to loop with a counter from 1:7, create the respective ta from this and instead of writing data to scalars, save them in arrays. Such as
ta=zeros(1,7);
qe=zeros(1,7);
for cnt=1:7
ta(cnt)=cnt*5+15;
qe(cnt)=...;
...
end
plot(ta,qe)
  댓글 수: 3
Michael Haderlein
Michael Haderlein 2015년 4월 17일
Better than before, but simply using the {} Code button right above the edit control would even increase readability.
Could my answer solve your problem? It does not seem as if you had inserted my suggestion in this code.
majid eid
majid eid 2015년 4월 17일
yes thank you very much michael, it worked :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by