필터 지우기
필터 지우기

How do i create a big line with 3 portions ?

조회 수: 1 (최근 30일)
sachin narain
sachin narain 2018년 4월 17일
편집: dpb 2018년 4월 17일
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.

  댓글 수: 1
sachin narain
sachin narain 2018년 4월 17일
Pefect.Thank you for the answer.Can you explain what you have done here?

댓글을 달려면 로그인하십시오.

추가 답변 (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