A problem caused by 'xlim' and 'axis equal'

조회 수: 10 (최근 30일)
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 29일
댓글: Mohammad Shojaei Arani 2023년 11월 29일
Hello,
I could not figure this problem. If you run the following then you get an error message
clc;
x=linspace(0,2*pi,1000);y1=sin(x);y2=cos(x);
subplot(2,1,1)
plot(x,y1,'-k');
xlim([-inf inf]);
ylim([-inf inf]);
xlabel('x');ylabel('y1');
legend('Sin');
axis equal;
subplot(2,1,2)
plot(x,y2,'-k');
xlim([-inf inf]);
ylim([-inf inf]);
xlabel('x');ylabel('y2');
legend('Cos');
axis equal;
I do not get any error if I remove 'xlim','ylim' stuff or if, instead, I renove 'axis eqaul'. I need to keep everything. How can I solve this annoying issue?
Thanks in advance!
Babak
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 11월 29일
You have to provide atleast one finite value when using xlim and ylim.
And setting x and y limits to (-Inf, Inf) does not make sense (atleast to me).
What exactly do you want to do?
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 29일
Thanks!
Now, I got the root of the problem.
I have to use xlim([-inf inf]) since I do not know, in advance, the size of my figure. At the same time
I want my x and y axes to be equal. I am making a matlab package and this is not about one or two figures
I want to make for myself. Therefpre, I do not know the limits and have to use xlim([-inf inf]).
So, how can I use xlim([-inf inf]) and axis equal at the same time?

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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 11월 29일
이동: Image Analyst 2023년 11월 29일
"So, how can I use xlim([-inf inf]) and axis equal at the same time?"
You can not. As I said before, atleast 1 input value to xlim/ylim must be finite.
"I want my x and y axes to be equal. "
Then provide the same limits to both axes.
"Therefpre, I do not know the limits and have to use xlim([-inf inf])."
MATLAB will adjust the limits automatically according to the given data.
  댓글 수: 3
Image Analyst
Image Analyst 2023년 11월 29일
To be explicit, just remove these lines entirely
xlim([-inf inf]);
ylim([-inf inf]);
and MATLAB will decide on "nice" limits to use automatically.
Mohammad Shojaei Arani
Mohammad Shojaei Arani 2023년 11월 29일
ok. thaks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by