Subplot in PlotButton Callback: Can a subplot be incorporated into the code of a plot button?

I am tryin to get several plots into one figure using the plot button callback. In the past, it would be easy to get several plots on figure by doing something like
subplot(3,1,1)
plot(angle1, velocity1)
title(' ')
ylabel(' ')
subplot(3,1,2)
plot(angle2, velocity2)
title(' ')
ylabel(' ')
subplot(3,1,3)
plot(angle3, velocity3)
title('')
ylabel(' ')
xlabel(' ')
pause;
Is this possible using a push button?

Antworten (2)

I think you must mean that you want a new subplot with each button press, is that correct? If so, do you want to limit the number of subplots created? You could do something like this for the pushbutton callback:
function [] = pb_callback(varargin)
N = get(gcbo,'userdata') % Use pushbutton handle.
if isempty(N) % You could also initialize this in createfcn.
N = 1;
elseif N>4 % Limit the user to 4 subplots.
disp('Maximum number of subplots already reached')
return
end
subplot(2,2,N)
plot(....) % Plot your stuff.
set(gcbo,'userdata',N+1); % Update the userdata.
Note that you could store the subplot count in guidata or wherever you want.

3 Kommentare

To clarify,
when I push the plot button on my GUI, I get a graph of the outport (desired result from my model).
I am wondering if it is possible to create a subplot of a second outport, on the same figure, but below the graphed results of the first outport. Ideally, this would happen when I push the plot button once.
It should be possible, did you try the code I gave at all?
sorry matt, I haven't tried it yet. I'm home and away from computers with matlab and I was just thinking about the problem. I'll try it as sooon as I can! Thanks.

Melden Sie sich an, um zu kommentieren.

Carlo, subplot() needs to know the number of plots ahead of time in order to size each one correctly. If you know the number of plots, then Matt Fig's code should be useful for you. If you do not know the number ahead of time, then using subplot() for this purpose would be tricky, as you would have to predict the area that subplot would want to allocate for the new plot and then you have to shrink and move your existing plots to make room before you do the subplot() [subplot will delete any existing axes that the new axes would overlay by even a single pixel.]
There are other possibilities, such as a using a scrollable pane of plots. I believe there is a Matlab File Exchange (FEX) contribution that implements scrollable panes of plots, but I am not sure if you need to specify the total area ahead of time for that contribution.

Gefragt:

am 9 Mär. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by