How to connect the plot point in matlab

1 次查看(过去 30 天)
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