MATLAB Answers

How to connect the plot point in matlab

2 ビュー (過去 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.

  0 件のコメント

サインイン to comment.

採用された回答

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 件のコメント

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
Jon
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.

サインイン to comment.

その他の回答 (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

サインイン to comment.

サインイン してこの質問に回答します。

製品


リリース

R2014a

Translated by