Loading and Saving Variables GUI

Hello,
I'd like to build a GUI in which some .mat files are loaded at the opening of the GUI, then some operations are performed by the user, and finally some variables are saved again as .mat files ( an updated version of the previous loaded) ready for a new run of the GUI.
I'm reading too much documentation on GUIDE, AppDesigner or programmaticaly through code and I'm very confused. I don't understand which way is the best to follow and how to set the correct strategy. Now I think I'm mixing too things, adding global variables and so on.
Since the GUI will be used by other people than me, I would like to understand how to manage the command load and save variables and which GUI environment is better to use.
Thank you for your help.

3 Comments

Rik
Rik on 11 Sep 2019
Edited: Rik on 12 Sep 2019
Personally I dislike GUIDE, especially for anything more complex than an axes and two buttons. The differences between AppDesigner and a programmatic GUI are mainly that one is class based and the other is function based. See below for my guide to avoid GUIDE.
One thing to keep in mind is that the I stands for interface. That means the meat of your program is the program itself. The GUI is just to allow a user to run your program. So things like saving mat files is not a difference for any of the three options.
One closing note: situations that require global variables are extremely rare.
My small guide to avoid GUIDE:
  • Make a figure (with f=figure;) and look into the doc for figure which properties you want to turn off (you probably want to set Menu and Toolbar to 'none')
  • Create buttons and axes and everything you need with functions like uicontrol and axes. Save the handles to each element to fields of a struct (like handles.mybutton=uicontrol(___);)
  • When you've finished loading all data (and saving it to fields of your handles struct), and creating all the buttons, save your handles struct to the guidata of your figure like this guidata(handles.f,handles);. (You can also use getappdata and setappdata)
  • You can set the Callback property of many objects. If you do, use a function name with an @ in front, or a char array that can be evaluated to valid code. (like @MyFunction or 'disp(''you pushed the button'')')
  • Callback functions will be called with two arguments: the first is a handle to the callback object, the second is eventdata that may contain special information. To get access to your data, just use handles=guidata(gcbo);. You can replace the gcbo function with the name of the first input to your callback function if you prefer.
  • More information about callbacks can be found in multiple places in the doc, for example here.
I agree with Rik: it really is much easier to write your own GUI: you get more control over functionality, more flexibility (e.g. nested functions to pass data between callbacks), and more compact code. Also:
  • Always obtain and refer to explicit handles for all graphics objects. Do not assume that gca, gcf, etc. will refer to the objects you need.
@Stephen, good point. I'll add it to my autohotkey file.

Sign in to comment.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Release

R2017a

Asked:

on 11 Sep 2019

Commented:

Rik
on 12 Sep 2019

Community Treasure Hunt

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

Start Hunting!