Sharing information between Callback functions in GUIDE

1 回表示 (過去 30 日間)
Johan Mihindukulasuriya
Johan Mihindukulasuriya 2019 年 11 月 10 日
回答済み: Rik 2019 年 11 月 13 日
I'm trying to pass the value that I get in the textbox of edit1_Callback into the pushbutton2_Callback but I keep getting the error message that z_slice is invalid no matter how many times I try to pass it in and even when using the handles method.
function edit1_Callback(hObject, eventdata, handles)
global z_slice;
z_slice=str2double(get(hObject,'String'))
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
sf = fit([handles.x3,handles.y3],handles.z3,'cubicinterp');
plot(sf,[handles.x3,handles.y3],handles.z3)
hold on
patch([handles.xmin,handles.xmin,handles.xmax,handles.xmax],[handles.ymin,handles.ymax,handles.ymax,handles.ymin],[z_slice,z_slice,z_slice,z_slice],'w','FaceAlpha',0.7);
title('3D Curve Fit w/Cubic Interpolation')
xlabel('X')
ylabel('Y')
zlabel('Value')

回答 (1 件)

Rik
Rik 2019 年 11 月 13 日
Because hObject is the handle to your pushbutton, you need to explicitly say you want to get the content of the edit box:
z_slice=str2double(get(handles.edit1,'String'))

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by