jojocleo 发表于 2008-5-29 09:59

GUI中不同控件间实时数据传递问题

我现在做了个GUI界面,需要在其中的两个控件中进行实时数据传递,就是控件1的数据是个变量,随时间变化,而控件2需要这个变量的值进行判断。但是我在运行控件2的时候控件1的命令就会停止,控件2调用的这个变量也就不随时间变化了,这个问题怎么解决?我把一个简单的程序附上,大家看看。
function display_Callback(hObject, eventdata, handles)
% hObject    handle to display (see GCBO)
% eventdatareserved - 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)
% eventdatareserved - 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)
% eventdatareserved - 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中的命令停止。

zhenghui 发表于 2009-10-11 09:40

参数的传递可以按照一下的思路进行操作,第一,用句柄(handles)传递;第二,把SUB中产生的数据发送到workspace中,main然后在从workspace中去读取;第三,如果不是实时的对数据进行操作,还可以把SUB产生的数据保存为一个*.mat文件,main然后在读取这个文件,进行参数的传递。暂时想到这些,具体的实现,可以慢慢再交流。
页: [1]
查看完整版本: GUI中不同控件间实时数据传递问题