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!