Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2008-03-06
年龄: 43
帖子: 2
声望力: 0 ![]() |
![]()
我现在做了个GUI界面,需要在其中的两个控件中进行实时数据传递,就是控件1的数据是个变量,随时间变化,而控件2需要这个变量的值进行判断。但是我在运行控件2的时候控件1的命令就会停止,控件2调用的这个变量也就不随时间变化了,这个问题怎么解决?我把一个简单的程序附上,大家看看。
function display_Callback(hObject, eventdata, handles) % hObject handle to display (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) for i=1:1000 set(handles.edit_output,'string',num2str(i)); setappdata(handles.figure1,'angle',i); pause(0.2) end %---------- function edit_output_Callback(hObject, eventdata, handles) % hObject handle to edit_output (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 edit_output as text % str2double(get(hObject,'String')) returns contents of edit_output % as a double %----------- function send_Callback(hObject, eventdata, handles) % hObject handle to send (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % global angle global s % a=get(handles.edit_input,'string'); % fwrite(s,a); %向com1口发送两个数据48和59 for i=1:100 getappdata(handles.figure1,'angle') pause(0.2) end %----------- output是显示窗口,把display中的变量i显示出来,i随时间变化,同时把i传递给send控件,运行send控件时,会使display中的命令停止。 |
![]() |
![]() |