Creating Graphical User Interfaces |
Plotting the Results Data
The GUI Plot button callback creates a plot of the run data and adds a legend. The data to plot is passed to the callback in the handles
structure, which also contains the gain settings used when the simulation ran. When a user clicks on the Plot button, the callback executes the following steps:
Plotting Into the Hidden Figure
The figure that contains the plot is created invisible and then made visible after adding the plot and legend. To prevent this figure from becoming the target for plotting commands issued at the command line or by other GUIs, its HandleVisibility
and IntegerHandle
properties are set to off
. However, this means the figure is also hidden from the plot
and legend
commands.
Use the following steps to plot into a hidden figure:
Parent
property to the figure handle, and save the axes handle.
Parent
properties to the handle of the axes.
Plot Button Callback Listing
Here is the Plot button callback.
function PlotButton_Callback(hObject, eventdata, handles) currentVal = get(handles.ResultsList,'Value');% Get data to plot and generate command string with color % specified
legendStr = cell(length(currentVal),1); plotColor = {'b','g','r','c','m','y','k'}; for ctVal = 1:length(currentVal); PlotData{(ctVal*3)-2} = handles.ResultsData(currentVal(ctVal)).timeVector; PlotData{(ctVal*3)-1} = handles.ResultsData(currentVal(ctVal)).outputVector; numColor = ctVal - 7*( floor((ctVal-1)/7) ); PlotData{ctVal*3} = plotColor{numColor}; legendStr{ctVal} = [handles.ResultsData(currentVal(ctVal)).RunName,... '; Kf=', ... num2str(handles.ResultsData(currentVal(ctVal)).KfValue),... '; Ki=', ... num2str(handles.ResultsData(currentVal(ctVal)).KiValue)]; end% If necessary, create the plot figure and store in handles % structure
if ~isfield(handles,'PlotFigure') | ~ishandle(handles.PlotFigure), handles.PlotFigure = figure('Name','F14 Simulation Output',... 'Visible','off','NumberTitle','off',... 'HandleVisibility','off','IntegerHandle','off'); handles.PlotAxes = axes('Parent',handles.PlotFigure); guidata(hObject, handles) end% Plot data
pHandles = plot(PlotData{:},'Parent',handles.PlotAxes);% Add a legend, and bring figure to the front
legend(pHandles(1:2:end),legendStr{:})% Make the figure visible and bring it forward
figure(handles.PlotFigure)
Removing Results from the List Box | The GUI Help Button |
© 1994-2005 The MathWorks, Inc.