How to connect the plot point in matlab

조회 수: 1 (최근 30일)
KARTHIKEYAN M
KARTHIKEYAN M 2020년 3월 16일
댓글: KARTHIKEYAN M 2020년 3월 16일
I use the plot commant to plot a graph. Example : Plot(lenght, tension, '-*') ;
But this comment only give the point.

채택된 답변

Jon
Jon 2020년 3월 16일
편집: Jon 2020년 3월 16일
First, you should avoid name your variable length, (which I think you mispelled in your example above as lenght) as length is a MATLAB command that gives the number of elements in an array. Using it as a variable will cause confusion, especially if you later use length as a command.
If you only get one point in your plot, I would suspect that your variable that you are plotting, tension, only has one element. Look at it in the works space tab to see. If so you will need to look back further in your code to see why it doesn't have as many elements as you expect.
  댓글 수: 3
Jon
Jon 2020년 3월 16일
편집: Jon 2020년 3월 16일
You could do something like this. Note you can use the code button on the MATLAB Answer toolbar to format your code nicely. I see now, looking at Image Analyst solution, second option, this is basically what he is suggesting, but maybe it is a little more concrete here using your code.
na=1;
lo=0.0408;
fmax=12.5;
m=0.0025;
vmax=0.2502;
k=30000;
csh=0.5;
cshort=1;
cleng=0.17;
cmul=1.5;
cpe=10;
pemax=0.8;
vn=0.001;
t=0.01;
x=0;
l=0.001;
fce=0;
la=(l/lo);
icnt = 0; % add counter
while(la<=2)
icnt = icnt+1; % increment the point counter
la(icnt)=(l/lo);
f1=exp((-(((l+x)/lo)-1)/csh)^2);
v=(vn/vmax);
if v ==1
f2=0;
elseif (-1<v)&&(v<0)
f2=((csh*(v+1))/(cshort-v));
elseif v>0
f2=((cleng+(v*cmul))/(cleng+v));
fce=fmax*na*f1*f2;
if x<0
fpe=0;
elseif x==0
fpe=((fmax/((exp(cpe))-1))*(exp((cpe*x)/(lo*pemax)))-1);
ft(icnt)=fce+fpe;
fap=(f1+(fpe/fmax));
fav=(ft(icnt)/fmax);
disp(fav);
l=l+0.005;
end
end
end
% plot results
plot(la,ft,'-*r');
xlabel('l/lo');
ylabel('tension');
KARTHIKEYAN M
KARTHIKEYAN M 2020년 3월 16일
This is working sir. Thank you for your help.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 3월 16일
Try indexing the vectors and using "hold on":
for k = 1 : whatever
allLengths(k) = whatever;
allTensions(k) = whatever;
plot(allLengths, allTensions, '-*');
hold on;
drawnow;
end
Or if you want, you can just call plot() once outside the loop rather than inside the loop:
for k = 1 : whatever
allLengths(k) = whatever;
allTensions(k) = whatever;
end
plot(allLengths, allTensions, '-*');
  댓글 수: 1
KARTHIKEYAN M
KARTHIKEYAN M 2020년 3월 16일
na=1; lo=0.0408; fmax=12.5; m=0.0025; vmax=0.2502; k=30000; csh=0.5; cshort=1; cleng=0.17; cmul=1.5; cpe=10; pemax=0.8; vn=0.001; t=0.01; x=0; l=0.001; fce=0; hold on; la=(l/lo); while(la<=2) la=(l/lo); f1=exp((-(((l+x)/lo)-1)/csh)^2); v=(vn/vmax); if v -1 f2=0; elseif (-1<v)&&(v<0) f2=((csh*(v+1))/(cshort-v)); elseif v>0 f2=((cleng+(v*cmul))/(cleng+v)); fce=fmax*na*f1*f2; if x<0 fpe=0; elseif x=0 fpe=((fmax/((exp(cpe))-1))*(exp((cpe*x)/(lo*pemax)))-1); ft=fce+fpe; fap=(f1+(fpe/fmax)); fav=(ft/fmax); disp(fav); plot(la,ft,'*r'); xlabel('l/lo'); ylabel('tension'); l=l+0.005; end end end
grid on;
Sir, this is my entire code its plot a graph with points.i dont know how to connect the points

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

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by