필터 지우기
필터 지우기

Setting different xlim for subplots

조회 수: 30 (최근 30일)
Anirban Mandal
Anirban Mandal 2021년 9월 30일
댓글: Mathieu NOE 2021년 9월 30일
I want to plot a lot of subplots(minimum 4*4). In each row, the function remains same but the xlim should change. As the number of subplots is high, it is convenient to use for loop for generating subplots. But there I am not being able to change the x limits. Here is a sample code.
a=-180:1:180;
b=sind(a);
c=cosd(a);
figure(1)
for i=1:2
subplot(2,2,i);
plot(a,b,'k','Linewidth',2)
subplot(2,2,i+2)
plot(a,c,'r','Linewidth',2)
end
I tried a sample one with 2*2 subplots and sinusoidal functions. The top row should provide sine curve plots and the bottom row should provide cosine curve plots. I am getting that. But I want to change the x limit of the curves(Like for the sine curves, one in the negative cycle and other in the positive cycle). Any help is appreciated.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 9월 30일
hello
maybe this ?
a=-180:1:180;
b=sind(a);
c=cosd(a);
figure(1)
xlimits = [0 180;-180 0];
for i=1:2
subplot(2,2,i);
plot(a,b,'k','Linewidth',2)
xlim(xlimits(i,:))
subplot(2,2,i+2)
plot(a,c,'r','Linewidth',2)
xlim(xlimits(i,:))
end
  댓글 수: 2
Anirban Mandal
Anirban Mandal 2021년 9월 30일
Okay, got an idea about how to introduce different ranges for the axes. Thanks a lot.
Mathieu NOE
Mathieu NOE 2021년 9월 30일
My pleasure !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by