MatlabGUI-调用相同的gui屏幕

MatlabGUI-调用相同的gui屏幕,matlab,user-interface,Matlab,User Interface,我尝试在matlab,GUI中,用户输入点作为输入和它们之间的连接 我有5个matlab文件-screen1.m,screen2.m,screen3.m,screen4.m,globalParams.m 在globalParams中,我有全局参数,所以我可以在屏幕GUI之间使用它们。 在屏幕1中,用户输入节点数(例如5)。当他按下下一步按钮时,回调函数调用“screen2();”。在screen2.m中,用户输入(x,y)坐标,当他按下下一步按钮时,回调函数调用“screen3();” 现在我要

我尝试在matlab,GUI中,用户输入点作为输入和它们之间的连接

我有5个matlab文件-screen1.m,screen2.m,screen3.m,screen4.m,globalParams.m

在globalParams中,我有全局参数,所以我可以在屏幕GUI之间使用它们。 在屏幕1中,用户输入节点数(例如5)。当他按下下一步按钮时,回调函数调用“
screen2();
”。在screen2.m中,用户输入(x,y)坐标,当他按下下一步按钮时,回调函数调用“
screen3();

现在我要求他填写节点I到节点j之间的连接(他需要填写节点I和j的编号)。如果只有1个连接,他将按下Finish按钮,回调函数将调用“
screen4();
,一切正常。否则(有多个连接),他按下Next按钮,回调函数调用“
screen3()”。
因此,当我们有超过1个连接时,我无法再次调用screen3..

当我调用下一个屏幕以关闭上一个屏幕时,是否还有其他方法? 因为当我们一次又一次地找到调用screen3的方法时,会打开很多GUI,这会让用户感到困惑和烦恼

一些代码:

在屏幕1中,下一步按钮:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen2();
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

screen3();
在屏幕2中,下一步按钮:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen2();
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

screen3();
在屏幕3中,单击“下一步”按钮,然后单击“完成”按钮:

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen3();

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
screen4();
在屏幕3中,我如何使用两个节点之间的连接:

function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double

global hopsMatrix;
i = str2num(get(handles.edit2, 'string'));
j = str2num(get(handles.edit1, 'string'));
hopsMatrix(i,j) = 1;

我不会再调用
screen3()
。您只需清除编辑字段,显示一条成功消息,然后让他重新开始

将数据评估(您当前在
edit2\u回调中的部分)移动到“下一步”按钮,然后在获得数据后

set(handles.edit1, 'String', '');
set(handles.edit2, 'String', '');
set(handles.text1, 'String', sprintf('Connection (%d, %d) was added.',i,j));
不要忘记在某处添加一个静态文本字段来显示消息(它应该会自动接收句柄
text1

这样,用户可以添加任意数量的节点,单击“下一步”清除字段并添加另一个连接,或者单击“完成”继续。
无需在
edit2
回调中添加与数据的连接(这也会带来一些问题,例如,如果用户首先输入第二个点,或者在第二个编辑字段中输入内容时注意到第一个点有错误)


至于删除,每个GUI在
handles.figure1
中都有其父图形的句柄,您可以在调用下一个图形之前关闭该句柄。因此,编写

close(handles.figure1);
screen2();

为什么调用
screen3()会有问题
又一次?有错误吗?它不起作用吗?它只是不再调用screen3..它只是做一件事而已您在edit2回调中评估数据的具体原因是什么?如果没有,请查看我的答案以获得更可靠的方法。您给我的第一个解决方案很好。但是第二个解决方案,使用close函数会导致我出错。对不存在的字段“figure”的引用。屏幕1>按钮1\u回调(第147行)关闭(handles.figure)时出错;