|
I hope I'm posting this in the correct place! I actually have two questions, but I think they are related to the same issue (my lack of understanding of handle graphics for one!). My apologies for the length of this post.
First a description of what I want to do.
I have written a GUI for an existing data set (3D human movement data) that provides the user with two ways to view the data:
1) using standard x-y plots of variables in the data set, and;
2) 3D animations of the movement data.
To acheive this my GUI has two axes -- one functions as a primary display (large, with various controls, etc.) and the other as a secondary display (small, no controls).
The user will have the option of plotting x-y data in one axes, say the primary display while viewing animated data in the secondary display. Furthermore, the user will be able to switch the axes display so that the animations appear iin the primary display and the plots in the secondary display.
I've already been able to acheive the basic goal - I can plot x-y data in one axes and, using a button control, I am able to dynamically switch the plot display between the primary and secondary axes of my GUI. No problemo.
Here is what I can't figure out how to do...
1) When I try to plot animations (using the patch function) the axes I have designated for the animation (say the primary axes) are simply ignored, and the data gets displayed using the entire GUI figure. I know that I am setting the axes handles correctly because I can switch a static plot between axes, so why not an animation? Please see the example code below. What am I doing wrong?
2) For the x-y plot functionality, I want the user to be able to plot multiple x-y graphs, up to a 4x4 display or something of that nature. I want these graphs to be within the confines of the original axes display (either primary or secondary)... This is where my knowledge of handle graphics and gui development falls short. In the .fig file I have created the axes inside a uipanel (thus two uipanels - a primary and secondary), and thus I should be able to create new axes dynamically using subplot that place all the plots within that uipanel. What I do not understand is how to go about doing this. How does one make subplot axes children of a uipanel, that can dynamically switch from one parent uipanel to another? Or am I going about this the wrong way?
% ============ some code showing the basic layout ==============
% plot data (pdata) and animation data (adata) are created from a model, and
% passed to GUI controls in the handles structure.
% Push button to plot x-y data in structure "pdata"
function pushbutton_plot_Callback(hObject, eventdata, handles)
if handles.paxis == 1, axes(handles.axes_first); end
if handles.paxis == 2, axes(handles.axes_second); end
plotdata(handles.pdata);
% Push button to animate x-y-z data in structure "adata"
function pushbutton_animate_Callback(hObject, eventdata, handles)
if handles.paxis == 2, axes(handles.axes_first); end
if handles.paxis == 1, axes(handles.axes_second); end
animdata(handles.adata);
% A simple function to plot x-y data in the current axes
function plotdata(pdata)
plot(pdata.x,pdata.y);
% A simple function to animate x-y-z "patch" data in the current axes
function animdata(adata)
axis vis3d; axis equal; axis off; % first set some axis properties
p = patch('Vertices',adata.vertices(1,:,:),...
'Faces'.adata.faces); % get handle of patch for 1st frame
for i = 1:n
set(p,'Vertices',adata.vertices(i,:,:)); % animate by updating patch data
end
=============== end of sample code =======================
The two push button controls above are used to plot and animate data in the two axes. The variable "handles.paxis" tells the program which axes to plot x-y data (and thus by default where to plot animation data). Another button (code not shown) allows the user to change the "handles.paxis" assignment. Boiled down examples of the plot and animate functions are also shown. Note that the assignment of axes happens just before these functions are called, so all the graphics should display in the assigned axes -- but this only works for the x-y plot and not the animation.
Now, with respect to the multi-plot problem, if I try to use subplot instead of plot in the plotdata function above, similarly, the designated axes get ignored and the data are plotted in the GUI figure. Clearly it is here or somewhere that I need to tell my program that subplot axes need to be children of the uipanel that is associated with the active axes (to allow dynamic switching), but I do not know how to do this.
Goodness, sorry for this lengthy post! Thanks in advance for any assistance.
Chris
|