How to connect the plot point in matlab
1 view (last 30 days)
Show older comments
I use the plot commant to plot a graph. Example : Plot(lenght, tension, '-*') ;
But this comment only give the point.
0 Comments
Accepted Answer
Jon
on 16 Mar 2020
Edited: Jon
on 16 Mar 2020
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 Comments
Jon
on 16 Mar 2020
Edited: Jon
on 16 Mar 2020
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');
More Answers (1)
Image Analyst
on 16 Mar 2020
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, '-*');
See Also
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!