using subplot(m,n,p,ax) in a loop
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi, If I have this plot
x = linspace(1,10);
y = sin(x);
plot(x,y)
title('Sine Plot')
And want to assign it to a subplot with the same axes, I will do
ax1 = gca;
subplot(2,1,1,ax1)
But now if I want a new plot at subplot(2,1,2) with the same axes, I can’t do
ax1 = gca;
subplot(2,1,2,ax1)
because it deletes the previous plot. How can I keep both plots?
Cheers, p.
댓글 수: 0
채택된 답변
Ingrid
2015년 6월 11일
you cannot define an axes handle in a subplot command because the subplot command generates an axes
You should just write
h1 = subplot(2,1,1)
plot(h1,x1,y1)
h2 = subplot(2,1,2)
plot(h2,x2,y2)
댓글 수: 2
Ingrid
2017년 2월 3일
when you type
doc image
you can learn that what you want is to not generate a new plot (A high-level function that calls newplot to determine where to draw the graphics objects and sets the following axes properties) as you are currently doing, but that you require A low-level function that adds the image to the current axes without calling newplot. The low-level function argument list can contain only property name/property value pairs. So basically you have to change your call to image so that you are plotting to the currently selected axes
hFig = figure;
for i= 1:12
% Subplot 1
figure(1)
hAX(i) = subplot(4,3,i); % i is the counter of the loop for example
xlim (hAX(i),[0 1]);
ylim (hAX(i),[0 100]);
box(hAX(i),'off');
hold(hAX(i),'all')
image('PropertyName',PropertyValue,...) % fill in for your specific case
colorbar;
end
추가 답변 (1개)
Salaheddin Hosseinzadeh
2015년 6월 11일
Just put figure outside the loop.
If you want to change each axis or maybe axes properties, use xlim ylim in your for loop you can only have
for i = 1:N
subplot(1,N);
plot(data);
xlim([-x,x]);
ylim([-y,y]);
end
something like this
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!