Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

자료 매번 검색하기 귀찮아서 만든 블로그

MATLAB - 두개의 x축 사용하여 그림 그리기 본문

Matlab

MATLAB - 두개의 x축 사용하여 그림 그리기

쿠키아버님 2023. 4. 3. 19:44

참고 자료 : https://kr.mathworks.com/help/matlab/creating_plots/graph-with-multiple-x-axes-and-y-axes.html

 

여러 개의 스케일과 좌표축 제한을 사용하여 데이터 표시하기 - MATLAB & Simulink - MathWorks 한국

이 예제의 수정된 버전이 있습니다. 사용자가 편집한 내용을 반영하여 이 예제를 여시겠습니까?

kr.mathworks.com

 

스케일이 다른 두개의 데이터를 동시에 그리고싶을 때 사용한다

 

예제 코드

 

x1 = 1:10;
y1 = rand(length(x1), 1);

x2 = 100:150;
y2 = rand(length(x2), 1);

x축의 스케일이 다른 두 그림을 한 figure에 담고싶을 때,

 

figure;

t = tiledlayout(1,2,'TileSpacing','compact');
bgAx = axes(t,'XTick',[],'YTick',[],'Box','off');
bgAx.Layout.TileSpan = [1 2];

%% x1, y1에 대한 그림 그리기
ax1 = axes(t);
plot(ax1, x1, y1)
xline(ax1,10,':');
ax1.Box = 'off';
xlim(ax1,[0 10])
xlabel(ax1, 'First Interval')

%% x2, y2에 대한 그림 그리기
ax2 = axes(t);
ax2.Layout.Tile = 2;
plot(ax2,x2, y2)
xline(ax2,100,':');
ax2.YAxis.Visible = 'off';
ax2.Box = 'off';
xlim(ax2,[100 150])
xlabel(ax2,'Second Interval')


%% Link the axes
linkaxes([ax1 ax2], 'y')