필터 지우기
필터 지우기

Updating 'Base' workspace values using a GUI

조회 수: 7 (최근 30일)
Craig Saunders
Craig Saunders 2018년 7월 30일
댓글: Stephen23 2018년 7월 30일
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
Craig Saunders
Craig Saunders 2018년 7월 30일
Thank you Stephen, however, regardless of this being recommended or not - would you kindly provide an example of how this could be done? The input dialog is basic and id prefer to design the GUI myself.
Cheers
Stephen23
Stephen23 2018년 7월 30일
@Craig Saunders: the second link in my comment above has many examples.

댓글을 달려면 로그인하십시오.

답변 (2개)

Dennis
Dennis 2018년 7월 30일
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
Craig Saunders
Craig Saunders 2018년 7월 30일
'Function definitions are not permitted in this context'.
Dennis
Dennis 2018년 7월 30일
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
Image Analyst 2018년 7월 30일
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
Craig Saunders
Craig Saunders 2018년 7월 30일
Thanks for your response. My main task is to change values stored in the base workspace which are linked to a Simulink model. I want to run the Simulink model and update the values in order to show a difference within the simulation. Ideally I'd like the values to be adjusted using a slider which would demonstrate these differences.
Craig

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by