Permanently updating the value of an Edit Text box to input values with a push button
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 6월 28일
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
Walter Roberson
2011년 6월 29일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!