MATLAB Answers

GUIDE - using the data of a Textbox to use it in other functions in the main

1 view (last 30 days)
Megan
Megan on 13 Dec 2019
Edited: Megan on 19 Feb 2020
I want to use the variable minVelocity in my main. the variable will me entered in the textbox of my gui after I press execute it will be saved.
But I can not use it in my main it does not work.

  0 Comments

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 13 Dec 2019
Just call this code to get minVelocity whenever you need it
minVelocity = str2double(handles.minVelocity.String);
The function will have to have access to the handles structure, which all GUI component callbacks will have.
See the FAQ for more options.

  6 Comments

Show 3 older comments
Image Analyst
Image Analyst on 17 Dec 2019
Your Analysis_Main function does not have access to handles unless you pass it in, because it's not a callback function. So you need to call it like this:
handles = Analysis_Main(handles);
Megan
Megan on 17 Dec 2019
I dont get it. I tried to do this but it didnt work. Where should i put this code snippet
Image Analyst
Image Analyst on 17 Dec 2019
Replace this
% --- Executes on button press in execute_button.
function execute_button_Callback(hObject, eventdata, handles)
minVelocity = str2double(get(handles.minVelocity_text, 'string'));
% Store the data in the "UserData" property of the GUI Figure
% This assumes that the hObject is a child of the GUI figure
data.minVelocity = minVelocity;
hObject.Parent.UserData = data;
disp(minVelocity)
Analysis_Main
with this
% --- Executes on button press in execute_button.
function execute_button_Callback(hObject, eventdata, handles)
minVelocity = str2double(get(handles.minVelocity_text, 'string'));
% Store the data in the "UserData" property of the GUI Figure
% This assumes that the hObject is a child of the GUI figure
data.minVelocity = minVelocity;
hObject.Parent.UserData = data;
disp(minVelocity)
handles = Analysis_Main(handles);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by