gui executing input parameter

2 views (last 30 days)
AStro
AStro on 8 Oct 2021
Commented: AStro on 11 Oct 2021
Hello,
I am working on gui (created with Guide). I have problem in finding the way to execute the change of parameter that is used later in the code to calculate some outputs. My gui has two Buttons and Edit Text field.
Button_1 opens the file with the exteranla data
Button_2 reads the data and makes some calculations
Edit Text field is used to insert the parameter that is used in calculations (by pressing Button_2)
My intension is to be able to change the parameter in Edit Text so that it is exectued by pressing Button_2 without the need of reopining the file (with Button_1). For now it seems that each time I do motifiaction to the Edit Text I have to open the file (with Button_1) and not only redo the calulations (with Button_2).
Below is part of my gui:
% --- Executes on button press in OpenFile.
function OpenFile_Callback(hObject, eventdata, handles)
handles=OpenFile(handles);
guidata(hObject, handles);
function input_p_Callback(hObject, eventdata, handles)
% hObject handle to input_p (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input_p as text
% str2double(get(hObject,'String')) returns contents of input_p as a double
% --- Executes during object creation, after setting all properties.
function input_p_CreateFcn(hObject, eventdata, handles)
% hObject handle to input_p (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Read.
function Read_Callback(hObject, eventdata, handles)
p = str2double(get(handles.input_p,'String'));
set(handles.input_p, 'String',num2str(p));
handles.p=p;
handles=Read(handles);
guidata(hObject, handles);
  1 Comment
Image Analyst
Image Analyst on 8 Oct 2021
Can you attach the .m and .fig files? We might not need to spend another 10 messages over another 8 hours if you do.

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 8 Oct 2021
@AStro you may need to post more code as it isn't clear what you might do with the data you read. But whatever it is, you can save the read data to the handles structure and then use that in your second button callback.
  14 Comments
AStro
AStro on 11 Oct 2021
Thank you @Geoff Hayes it finally works :-) Thank you for your time all the way through

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by