Permanently updating the value of an Edit Text box to input values with a push button

3 Ansichten (letzte 30 Tage)
Hi,
My GUI uses several Edit Text boxes for setting numeric variables that are used within my main code. Because certain parameters may change and shall be specified by the user, I need a way of saving new values into these Edit Text boxes and keeping them permanently i.e. keep the values that the user enters even if I close MATLAB and open it again etc.
So far I have managed to set the String property of my Mass_tb Edit Text handle using the “set” function to set its string to the variable “var”. This happens when a push button with the tag “SetDynDef_pb” is pressed:
function SetDynDef_pb_Callback(hObject, eventdata, handles) get(handles.AvT_cb,'value'); var = get(handles.Mass_tb,'string'); set(handles.Mass_tb,'String',var);
This does update the value of the string to the correct value when I run the code once, but when I close the GUI and run the program again, the value changes back to what I initially set in the Property Inspector from GUIDE (when I built the GUI). I need it to keep the value specified with var from previous runs when the user presses the push button.
Is this doable? I’m sure there’s a way but I only just started with matlab GUIs a few days ago so I’m a bit stuck.
I would very much appreciate any help you could give me!
Thanks

Antworten (2)

Walter Roberson
Walter Roberson am 28 Jun. 2011
You would have to re-save the .fig file /OR/ you would have to write a routine that saved the values in to a file and and another routine to load saved parameters and set() the handles appropriately.
  2 Kommentare
Earle
Earle am 29 Jun. 2011
It seems to be that the easiest way would be to save the .fig file, is that right? How do I do this, and would this recall the last state of all the widgets?
Thanks for your help!
Walter Roberson
Walter Roberson am 29 Jun. 2011
I find that I do not like the idea of re-saving the .fig file. Possibly that is partly because _I_ would not use a .fig file in the first place: I prefer to place all of the elements programmatically, which allows me to adapt to user font size preferences and to the user's screen size.
I have not looked at Doug's video to see what he recommends.
I save the key state variables as a structure in a .mat file. User preferences, though, I use uigetpref() and uisetpref() for, which MATLAB saves to a file by itself.

Melden Sie sich an, um zu kommentieren.


Paulo Silva
Paulo Silva am 28 Jun. 2011

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by