Effacer les filtres
Effacer les filtres

How do i create a big line with 3 portions ?

1 vue (au cours des 30 derniers jours)
sachin narain
sachin narain le 17 Avr 2018
Modifié(e) : dpb le 17 Avr 2018
i want to plot a line with 3 portions : 1) 0-500 with a slope of 10
2) 500-800 with 0 slope
3) 800-1000 with a slope of 10
in Matlab.It should look something like the picture i have attached.I am new to matlab.Kindly help

Réponse acceptée

dpb
dpb le 17 Avr 2018
Modifié(e) : dpb le 17 Avr 2018
hF=figure;                 % make new figure, save handle to it
X=[0;500;800;1000];        % given X values
Y=[0;0;0;0];               % need Y for 3d plot even if 0
Z=[0;10*500;10*500;10*500+200*10];  % Z based on description given of line
hL=plot3(X,Y,Z)            % make the 3D plot, save handle if want modify properties
hAx=gca;                   % get the handle for current axes to mung on 'em
xlabel('X'),ylabel('Y')    % obvious??
ylim([-10,10])             % shrink the y-axis
grid on                    % make grid show up for accent
rat=get(hAx,'DataAspectRatio');  % retrieve the axis ratio array
rat(1)=1;                  % shorten the x-ratio to shrink y/z sizes comparatively--arbitrary
set(hAx,'DataAspectRatio',rat) % reset to that ratio

The only tricky part is that of setting the plot aspect ratio to make it look long and skinny like the original; read up on how that works--do a search in the doc search for dataaspectratio and you'll find a section on 'Manipulating Axes Aspect Ratio' that 'splains all about it.

hAx.ZTtick=[0 10000];
hAx.FontSize=6;
y=[1 1 1]*0.95; hF.Color=y;

produces

from which to start...albeit the background shading doesn't seem to show here as it does on monitor for some reason(*)...salt to suit.

(*) Oh, all that gets saved is the axes, not the full figure in the jpeg...

ADDENDUM

Z=[0;10*500;10*500;10*500+200*10];  % Z based on description given of line

Clearly the above way to generate the Z values is only sensible when there are so few segments and the line definition/values are such as to make it trivial to write what each line segment end values are by inspection.

  1 commentaire
sachin narain
sachin narain le 17 Avr 2018
Pefect.Thank you for the answer.Can you explain what you have done here?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by