How do i create a big line with 3 portions ?

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

采纳的回答

dpb
dpb 2018-4-17
编辑:dpb 2018-4-17
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by