straight line doesn't show in plot

18 visualizaciones (últimos 30 días)
Povilas Vaitukaitis
Povilas Vaitukaitis el 15 de Nov. de 2016
Comentada: dpb el 16 de Nov. de 2016
Horizontal line doesn't appear in the plot for some reason. if I add 'x' or different line marker in the plot command it appears in the plot.
Scipt:
%%Stress distribution in the thick-walled and thin-walled cylinder along the cylinder wall
%%Constants and radial distance through the wall
Pi=13.1; % N/mm^2 internal pressure
d0=68; % mm outer radius
N=100; % number of points through the wall
t=6; % mm wall thickness
a=(d0-2*t)/2; % mm internal radius
b=d0/2; % mm external radius
k=b./a; % constant
r=linspace(a,a+t,N); % mm radial distance from the centre
p=(r-a)/t; % parametric distance
%%thin-walled cylinder
thinsigma1=Pi*a./t; % 1st principal stress
thinsigma2=Pi*a./(2*t); % 2nd principal stress
thinsigma3=0; % 3rd principal stress
%%thick-walled cylinder
thicksigma1=(Pi/((k^2)-1))*(1+(b^2)./(r.^2)); % 1st principal stress
thicksigma2=Pi/((k^2)-1); % 2nd principal stress
thicksigma3=(Pi/((k^2)-1))*(1-(b^2)./(r.^2)); % 3rd principal stress
%%plot the results for thin-walled cylinder
plot(p,thinsigma1,'kx')
title('Thin-walled principal stress versus parametric distance')
legend('1st principal stress')
xlabel('Parametric distance')
ylabel('1st principal stress, N/mm^2')
figure()
plot(p,thinsigma2,'kx')
title('Thin-walled principal stress versus parametric distance')
legend('2nd principal stress')
xlabel('Parametric distance')
ylabel('2nd principal stress, N/mm^2')
figure()
plot(p,thinsigma3,'kx')
title('Thin-walled principal stress versus parametric distance')
legend('3rd principal stress')
xlabel('Parametric distance')
ylabel('3rd principal stress, N/mm^2')
%%plot results for thick-walled cylinder
figure()
plot(p,thicksigma1)
title('Thick-walled principal stress versus parametric distance')
legend('1st principal stress')
xlabel('Parametric distance')
ylabel('1st principal stress, N/mm^2')
figure()
plot(p,thicksigma2)
title('Thick-walled principal stress versus parametric distance')
legend('2nd principal stress')
xlabel('Parametric distance')
ylabel('2nd principal stress, N/mm^2')
figure()
plot(p,thicksigma3)
title('Thick-walled principal stress versus parametric distance')
legend('3rd principal stress')
xlabel('Parametric distance')
ylabel('3rd principal stress, N/mm^2')
line doesn't appear in the first 3 figures (in this script I put 'kx' so it appears) and in figure 5.
anyone knows why it is so?

Respuesta aceptada

dpb
dpb el 15 de Nov. de 2016
Editada: dpb el 16 de Nov. de 2016
Second posting today with same issue...serendipity strikes again!!! :)
>> whos p thinsig*
Name Size Bytes Class Attributes
p 1x100 800 double
thinsigma1 1x1 8 double
thinsigma2 1x1 8 double
thinsigma3 1x1 8 double
>>
All the y values are single points--when given a vector of x values but a single y, plot draws a line for each x value consisting of the single point. Hence, you get a dotted line by default or the markers when using the 'x' marker type.
If it really is intended to be a horizontal line, no point in filling a full array, but do have to fix up the plotting command somehow...
plot(p,repmat(thinsigma1,size(p)),'k')
is effective but a hammer.
plot(p([1 end]),repmat(thinsigma1,1,2),'k')
is more efficient in memory.
  2 comentarios
Povilas Vaitukaitis
Povilas Vaitukaitis el 15 de Nov. de 2016
thank you!
dpb
dpb el 16 de Nov. de 2016
No problem...was, however, curious event of two unrelated cases of the same symptom showed up on same day and I don't recall it ever in the time since I started watching the forum...
BTW, if have Stat and Machine Learning TB, there's a prepackaged function refline to add a baseline included there that's some "syntactic sugar" to accomplish the deed. Seems like a useful additive method to the plot function instead of squirreling away in a toolbox, however. But, of course, it's a pretty trivial addition.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by