What is the syntax I can use to save an axes that I defined in a code file into the handles structure, and how can I access this handle from other code files?
MATLAB: How to save/access an axes’s properties using the handles structure
axeshandles
Related Solutions
By writting the code like this:
%Setting the uipanel1 height, width and position as figure1
handles.uipanel1.Position = [0 0 handles.figure1.Position(3) handles.figure1.Position(4)];%This line of code has to come before creating the tab group, otherwise the
%tabs won't have the same width height and position as figure 1, only the
%first one will.
% Create tab group with SelectionChangedFcn
handles.tgroup = uitabgroup('Parent', handles.figure1,'TabLocation', 'top','SelectionChangedFcn',... @(hObject,eventdata)Frogsim('tgroup_SelectionChangedFcn',hObject,eventdata,guidata(hObject))); % This line tells the uitabgroup function that the name of the callback
% function for the selection change is named tgroup_SelectionChangedFcn
% , and also sends in the input argument guidata(hObject) which is the
% updated structure of handles and data , the eventdata is sent
% automatically.
handles.tab1 = uitab('Parent', handles.tgroup, 'Title', 'Materials and Optics selection');handles.tab2 = uitab('Parent', handles.tgroup, 'Title', 'Dispersion graphs');handles.tab3 = uitab('Parent', handles.tgroup, 'Title', 'My Tab Label 3');% Place panels into each tab
set(handles.uipanel1,'Parent',handles.tab1)set(handles.uipanel2,'Parent',handles.tab2)set(handles.uipanel3,'Parent',handles.tab3)% Reposition each panel to same location as panel 1
set(handles.uipanel2,'position',get(handles.uipanel1,'position'));set(handles.uipanel3,'position',get(handles.uipanel1,'position'));
Then the SelectionChangedFcn callback for the tab group called tgroup is set correctly. In this case my gui is called Frogsim , if your gui is called mygui then the third line should look like this:
@(hObject,eventdata)mygui('tgroup_SelectionChangedFcn',hObject,eventdata,guidata(hObject)));
Later in the code I wrote the SelectionChangedFcn for tgroup like this:
% --- Executes on selection change of tabs in tgroup tab group.
function tgroup_SelectionChangedFcn(hObject, eventdata, handles)% hObject handle to tgroup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
And then you can add whatever code you want to the selection change function.
To explain better what the third line did, the line of code:
@(hObject,eventdata)Frogsim('tgroup_SelectionChangedFcn',hObject,eventdata,guidata(hObject)));
creates an anonymous function that accepts the arguments
hObjecteventdata
then the anonymous function calls the function:
Frogsim('tgroup_SelectionChangedFcn',hObject,eventdata,guidata(hObject)));
what that does is to call the tgroup_SelectionChangedFcn function within Frogsim with arguments hObject and eventdata (That were passed inside by the anonymous function) and then the 3rd input argument is guidata(hObject) which will give the updated structure of handles and user data in a guide built gui, and that corresponds to the 3rd arguments of SelectionChangedFcn which is
handles
The textboxes in a GUI not printing in the same color as the background is an expected behavior.
A workaround for printing the textboxes in white color is to set the background color of the textboxes to white. The color of the textboxes can then be reverted to the original color after the printing is completed. The following code can be added to the Shortcut to accomplish this task.
% Show Hidden Handles to identify the GUI figure
set(0,'showHiddenHandles','on')% Identify the GUI figure
figureHandle = findobj(0,'Type','Figure');% Extract the GUI's children
childrenHandles = get(figureHandle,'Children');% Identify the textbox object handles
textBoxHandles = findobj(childrenHandles,'Style','text');% Store the original background color of the textbox
originalBGColor = get(textBoxHandles(1),'BackgroundColor');% Set the background color of textboxes to white
set(textBoxHandles,'BackgroundColor','w')% Print the GUI figure
print(figureHandle)% Revert the background color of textboxes to the original color
set(textBoxHandles,'BackgroundColor',originalBGColor)
Note if using PRINTDLG (or other substitutions for PRINT) that you may need to allow printing to finish before the last line
set(textBoxHandles,'BackgroundColor',originalBGColor)
can be executed. Simply insert a PAUSE command or manually remove this last line and execute it separately.
Related Question
- How to set handles on multiple figures using loop
- Pushbutton callback problem to update the colors in GUI. I want to update the background colors when the button is pushed and save the existing color values.
- GUI handles does not update
- How to reset the axes in this situation of the GUI
- GUI: Make pannel visible/invisible with buttonpress
Best Answer