Updating 'Base' workspace values using a GUI
Ältere Kommentare anzeigen
Hi all,
I would like to update a set of values in my 'base' workspace via a GUI by getting a user to enter values into separate 'edit text' fields and once a button is clicked, all values are sent to the 'base' workspace and updated. I have tried inputdlg however this is very basic and I'd prefer if someone provided an example using uicontrol or GUIDE.
I don't mind doing this via GUIDE or programmatically, however I'm completely new to this so I'd love to see an example code that I can use which simply allows a user to enter a value, hit a button, and the value then updates in the 'base' workspace.
Please see the example of where I'd like to start via the image.
3 Kommentare
Original question:
"... which simply allows a user to enter a value, hit a button, and the value then updates in the 'base' workspace."
Dynamically accessing variables in other workspaces is not recommended. It is much more reliable and more efficient to pass variables as input/output arguments.
Craig Saunders
am 30 Jul. 2018
Stephen23
am 30 Jul. 2018
@Craig Saunders: the second link in my comment above has many examples.
Antworten (2)
Dennis
am 30 Jul. 2018
Here is an example how you can achieve what you asked for, however if you decribe what you want to do we probably come up with a better/safer/quicker solution.
tf=uicontrol('style','edit','position',[100,20,100,20]);
button=uicontrol('style','pushbutton','callback',{@badidea,tf});
function badidea(~,~,tf)
A=tf.String;
evalin('base',strcat('A=',A))
end
6 Kommentare
Craig Saunders
am 30 Jul. 2018
Dennis
am 30 Jul. 2018
try to save the function as seperate .m file. I am not sure when Matlab introduced dot notation, this should work with older versions:
function badidea(~,~,tf)
A=get(tf,'String');
evalin('base',strcat('A=',A))
end
Craig Saunders
am 30 Jul. 2018
Dennis
am 30 Jul. 2018
You get some kind of error message?
Craig Saunders
am 30 Jul. 2018
Dennis
am 30 Jul. 2018
You are copy & pasting everything in command line? Either save and run it as script or save the function as badidea.m and run the other 2 lines.
Image Analyst
am 30 Jul. 2018
0 Stimmen
I agree with Stephen that it's not recommended. There are ways to share data. See the FAQ: https://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
1 Kommentar
Craig Saunders
am 30 Jul. 2018
Kategorien
Mehr zu Scripts finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!