如何从MATLAB中的另一个按钮调用按钮

时间:2013-06-15 21:52:35

标签: matlab callback

我有一个包含两个按钮的简单GUI,一个用于播放凸轮流,另一个用于停止它。

function Play_callback(hObject,eventdata,handles)

Play1 = evalin('base','PlayCam1');
Play2 = evalin('base','PlayCam2');

while (1)
if(Play1 == 1)
...CAM1 STREAM...
end
if(Play2 == 1)
...CAM2 STREAM...
end
end

function StopCam1(hObject,eventdata,handles)
assignin('base','PlayCam1',0);
Play_callback(hObject,eventdata,handles);

以上代码剪辑会按下按钮"Play"上的两个凸轮,但我需要单独控制每个凸轮的"STOP",因此,如果我点击"StopCam1""PlayCam1"等于0,并再次调用"Play"按钮来流式传输cam2而不是cam1。 MATLAB刚冻结,为什么会这样?

1 个答案:

答案 0 :(得分:0)

您需要在while循环中重新分配Play1和Play2变量:

function Play_callback(hObject,eventdata,handles)

Play1 = evalin('base','PlayCam1');
Play2 = evalin('base','PlayCam2');

while (1)
Play1 = evalin('base','PlayCam1');
Play2 = evalin('base','PlayCam2');
if(Play1 == 1)
...CAM1 STREAM...
end
if(Play2 == 1)
...CAM2 STREAM...
end
end

function Play_callback(hObject,eventdata,handles)

while (1)
if(evalin('base','PlayCam1')== 1)
...CAM1 STREAM...
end
if(evalin('base','PlayCam2')== 1)
...CAM2 STREAM...
end
end