xlim and ylim not working for plot

조회 수: 258 (최근 30일)
Poulomi
Poulomi 2022년 12월 19일
답변: Image Analyst 2022년 12월 19일
I wanted to plot a line and wanted to generate several figures. I wanted all of the plots to have the same axes but xlim and ylim are not being incorporated in the plots generated.
for i = 1:(timepoint+1)
figure(1)
hold on
plot(whole(j:j+i,1),whole(j:j+i,2), '--or')
ylim = [-2 5];
xlim = [0 20];
F(i) = getframe(gcf) ;
drawnow
end
I have tried this solution : xlim-is-not-working, but then I get the following error:
Array indices must be positive integers or logical values.

채택된 답변

DGM
DGM 2022년 12월 19일
편집: DGM 2022년 12월 19일
You're creating two new variables called xlim and ylim. You're not actually using the functions called xlim() and ylim().
ylim([-2 5]);
xlim([0 20]);
The reason you're getting an error is because you haven't cleared the variables you made. Once you clear the workspace or specifically clear those two variables, you can use the functions of the same name.
clear xlim ylim
Also, you should probably put the drawnow() call before you capture the frame.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 12월 19일
@DGM gave you the answer, but I just thought I'd add on some extra optional stuff, like if you want to take all your plots and make a movie out of them. See attached demo.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by