gui executing input parameter

1 ビュー (過去 30 日間)
AStro
AStro 2021 年 10 月 8 日
コメント済み: AStro 2021 年 10 月 11 日
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 件のコメント
Image Analyst
Image Analyst 2021 年 10 月 8 日
Can you attach the .m and .fig files? We might not need to spend another 10 messages over another 8 hours if you do.

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2021 年 10 月 8 日
@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 件のコメント
AStro
AStro 2021 年 10 月 11 日
Thank you @Geoff Hayes it finally works :-) Thank you for your time all the way through

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by