声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1583|回复: 1

[GUI界面] GUI中不同控件间实时数据传递问题

[复制链接]
发表于 2008-5-29 09:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我现在做了个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中的命令停止。

本帖被以下淘专辑推荐:

回复
分享到:

使用道具 举报

发表于 2009-10-11 09:40 | 显示全部楼层
参数的传递可以按照一下的思路进行操作,第一,用句柄(handles)传递;第二,把SUB中产生的数据发送到workspace中,main然后在从workspace中去读取;第三,如果不是实时的对数据进行操作,还可以把SUB产生的数据保存为一个*.mat文件,main然后在读取这个文件,进行参数的传递。暂时想到这些,具体的实现,可以慢慢再交流。

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-6-7 16:08 , Processed in 0.062875 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表