create a subplot in an existing axes

8 次查看(过去 30 天)
Steffen
Steffen 2011-5-6
Hi, i have a GUI containing 2 axes objects. in the first axes i do a normal line plot. in the second axes i want to place multiple subplots using the command plotmatrix. however i dont get it to work at all.
first time i call the function that does both plots, the line plot is working, while the second axes object just disappears (i think its made invisible by the plotmatrix command, but the subplots dont show up).
if i call the function again i get following error:
??? Error using ==> set
Invalid handle object.
Error in ==> newplot at 66
set(fig,'nextplot','add');
...
interesting is that the error occurs while trying to do the line plot and the invalid handle refers to fig, which is - i suppose - the handle to the figure. so what does plotmatrix do with the figure handle????
heres the code for the plots:
function plotValues(handles)
plot(handles.axes1, handles.plotValues);
[H,AX,BigAx,P] = plotmatrix(handles.axes_nodes,handles.nodeValues);
end
who can help?? thanks in advance!!
cheers, steffen

回答(1 个)

Patrick Kalita
Patrick Kalita 2011-5-6
I think the problem you're seeing is a result of the fact that plotmatrix sets the figure's NextPlot property to 'replace'.
For clarity, here's a small example that illustrates the problem as I understand it:
f = figure;
a1 = subplot(2,1,1);
a2 = subplot(2,1,2);
x = randn(50,3); y = x*[-1 2 1;2 0 1;1 -2 3;]';
plot(a1, 1:10);
plotmatrix(a2, y)
So far so good, but ...
>> get(f, 'NextPlot')
ans =
replace
>>
Usually, that would say 'add' for a figure (that's the default, anyway). So with that property set to 'replace', the figure essentially deletes all its current contents before anything new is added. That's why if you now do this...
plot(a1, 1:10);
... you'd see the plotmatrix plot go away.
To work around this, you can manually set the figure's NextPlot property after calling plotmatrix:
f = figure;
a1 = subplot(2,1,1);
a2 = subplot(2,1,2);
x = randn(50,3); y = x*[-1 2 1;2 0 1;1 -2 3;]';
plot(a1, 1:10);
plotmatrix(a2, y)
set(f, 'NextPlot', 'add')
Now you can re-do the plots without error:
plot(a1, rand(5));
plotmatrix(a2, rand(3))
set(f, 'NextPlot', 'add')
  1 个评论
Patrick Kalita
Patrick Kalita 2011-5-6
Oh, I should also point out that there are reasons why plotmatrix sets the NextPlot property like that. It's mostly for when you're calling these commands interactively at the command window, without carefully managing your handles. But when you really want to control where your plots go (by providing axes handles like you're doing), you need to override this behavior.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by