I am trying to create 2 subplots in a figure, theta_1 vs. t and theta_2 vs. t. The range of t in both plots is 10. There are the same amount of data points in both plots. When I run the code however, the second subplot's range of t is increased
This is my code:
figure(1)
grid on
P1 = subplot(2,1,1)
plot(t,v(1,:),'linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_1','fontSize',14);
P2 = subplot(2,1,2)
plot(t,v(2,:),'r','linewidth',2)
h=gca;
get(h,'fontSize')
set(h,'fontSize',14)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
xlim(P2, [0 10]);%trying to specify xlim
fh = figure(1);
set(fh, 'color', 'white');
I even tried to specify the xlim for the second subplot but it made no difference. What am I doing wrong?

댓글 수: 3

hello
1/ there are no NaN's in your data ?
2/ what would it give if you comment those lines (lower subplot) :
% h=gca;
% get(h,'fontSize')
% set(h,'fontSize',14)
NB : you're doing this only on the lower subplot - any reason for ?
dpb
dpb 2021년 1월 27일
h=gca;
get(h,'fontSize')
set(h,'fontSize',14)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
xlim(P2, [0 10]);%trying to specify xlim
Don't juse gca at all here; use the handles to the subplots exclusively.
It doesn't make any sense from just looking at the code that the range for the x axis is any different presuming the two t vectors are really the same t at the time the plot was created.
But, without the data it's not possible to prove, but cleaning it up and redoing would be the first step--
figure
P1 = subplot(2,1,1);
plot(t,v(1,:),'linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_1','fontSize',14);
P2 = subplot(2,1,2);
plot(t,v(2,:),'r','linewidth',2)
xlabel('t','fontSize',14);
ylabel('\theta_2','fontSize',14);
Amrtanshu Raj
Amrtanshu Raj 2021년 2월 1일
Hi,
can you share the data?

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

답변 (0개)

카테고리

제품

릴리스

R2020b

질문:

2021년 1월 27일

댓글:

2021년 2월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by