gui executing input parameter
2 次查看(过去 30 天)
显示 更早的评论
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
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
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 个评论
Geoff Hayes
2021-10-11
handles.p=p;
you are replacing this handle with a numeric value that represents the minimum peak distance and so this will invalidate the handle. This line of code should be removed. I know you have said that this causes problems elsewhere in the code and so that code should be corrected. I see that in CWT_Read.m you do
p = handles.p;
This is incorrect as p is a handle. Replace this with
p=str2double(get(handles.p,'String'));
instead.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!