To start a GUI in Matlab just type "guide" in the command window. You can then drag and drop object, and change their properties with a double click.
Load a file using a browser
Get the path of a file and load it:[FileName,PathName] = uigetfile('*.mat','Select the MATLAB matrix');
str = load([PathName, FileName]);
working with variables
Matlab define a set of function which allow the user to define the possible interaction with the objects. This function can be access with the callback function (to generate it just do a right click on the object and go in the callback section).
One of the important issue with this methods is that all the data have to be loaded and saved each time you change of function.
The natural workflow is:
function pushbutton1_Callback(hObject, eventdata, handles)
% load the dataor getappdata and setappdata.
var = evalin('base', 'varName');
...
% manipulation
...
% save the data
assignin('base', 'varName', var);
Get and set properties from a callback
To get the value of a property (for example the value of a slider):get(handles.slider2, 'Value');and to set a property (for example to define the text of a edit object):
set(handles.edit1, 'string', 'text');
Sometimes finding the handles of an object can be a bit tricky. There is a special function called findobj which allow to do it. An easy way to use it it to look for the 'Tag' of the object.
findobj('Tag', 'edit1')
Display images/graphs
Do display an image you have to add a axis object.
The next step is to select the axes.
axes(handles.axes1);
and finally to plot the image:
imagesc(img);
Ps: to remove the axis it is possible to use axis off
Save a file using a browser
The following function open a browser and allow to save a fileuisave('varName');
Further reading: http://www.mathworks.com.au/discovery/matlab-gui.html
Video example: http://www.mathworks.com.au/videos/creating-a-gui-with-guide-68979.html
Full documentation: http://www.mathworks.com.au/help/matlab/gui-building-basics.html
No comments:
Post a Comment