필터 지우기
필터 지우기

Draw multi graphs in one figure

조회 수: 1 (최근 30일)
Reji G
Reji G 2023년 6월 23일
댓글: Reji G 2023년 6월 23일
How to draw multi plots with same x axis and different ranged y axis in a same figure? (See the x axis and y axis values written in the image attached) .
clc;
close all;
t=0:0.000001:0.1;
x=sin(100*t);
y=cos(100*t);
plot(t,x);
hold on
plot(t,y);

채택된 답변

Ergin Sezgin
Ergin Sezgin 2023년 6월 23일
Hi Reji,
You can use subplot function to create axes in tiled positions which might be useful for your case.
However, If you need something similar to what you draw in your attachment, you can trick figure to add some offset to one of your arrays and change y axes labels to appropriate strings. Check the following code block:
clc
clear
close all;
t = 0:0.000001:0.1;
x = sin(100*t);
y = cos(100*t);
y = y + 3; % Offset
figure
plot(t,x);
hold on
grid on
plot(t,y);
yTickLabels = string([-1 -0.5 0 0.5 1 0 -1 -0.5 0 0.5 1]);
set(gca, 'yticklabel', yTickLabels)
Good luck
  댓글 수: 1
Reji G
Reji G 2023년 6월 23일
How to hide the center(1 0 -1)ticklabels alone ?

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

추가 답변 (1개)

Aakash
Aakash 2023년 6월 23일
You can achieve the desired outcome using subplot function as below:
t=0:0.000001:0.1;
x=sin(100*t);
y=cos(100*t);
figure;
subplot(2, 1, 1); % First subplot
plot(t, x);
ylim([-1 1]);
title('Plot 1');
subplot(2, 1, 2); % First subplot
plot(t, y);
ylim([-1 1]);
title('Plot 2');
  댓글 수: 1
Reji G
Reji G 2023년 6월 23일
Thank you for the response. Subplot/tiledlayout will create plots in individual boxes. But I need multi plots in One box. Please see my hand sketch.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by