Matlab Gui更新阴谋与popmenu
问题描述:
我有一个matlab Gui程序,它从串口获取输入数据并将它们绘制在图形中。 Gui有几个选项卡。在第二个选项卡中,我有一个popmenu,它允许我选择要绘制的数据。Matlab Gui更新阴谋与popmenu
回调函数
function popupCallback(src,~)
val = get(src,'Value');
% Second tab selected
if val == 2
try
while (get(xbee, 'BytesAvailable')~=0 && tenzo == true)
% reads until terminator
sentence = fscanf(xbee, '%s');
% Collect data to plot
getDataRoutine(sentence)
%Plot them
h1 = subplot(3,1,1,'Parent',hTabs(3));
plot(h1,index,gxdata,'r','LineWidth',2);
h2 = subplot(3,1,2,'Parent',hTabs(3));
plot(h2,index,gydata,'b','LineWidth',2);
h3 = subplot(3,1,3,'Parent',hTabs(3));
plot(h3,index,gzdata,'g','LineWidth',2);
end
end
end
当我选择在从串行字符串被分析popmenu第二个选项,数据被存储在变量,然后绘图。精细。
问题:只有当我点击在popmenu第二个选项
数据被绘制。我怎样才能获得“实时”绘制的数据?
答
好吧,我用三个计时器在0.1秒
申报定时器恒定速率首先执行的情节任务。
global gyroTimer;
gyroTimer = timer('ExecutionMode','FixedRate','Period',0.1,'TimerFcn',{@graphGyro});
global angleTimer;
angleTimer = timer('ExecutionMode','FixedRate','Period',0.1,'TimerFcn',{@graphAngles});
global accTimer;
accTimer = timer('ExecutionMode','FixedRate','Period',0.1,'TimerFcn',{@graphAcc});
在popmenu回调函数当相应的选项被选中
% drop-down menu callback
function popupCallback(src,~)
%# update plot color
val = get(src,'Value');
% Gyro
if val == 2
start(gyroTimer);
stop(angleTimer);
stop(accTimer);
end
% Accelerometer
if val == 3
stop(gyroTimer);
stop(angleTimer);
start(accTimer);
end
% Magnetometer
if val == 4
stop(gyroTimer);
start(angleTimer);
stop(accTimer);
end
end
创建绘图功能
function graphAngles(obj,event,handles)
% To debug uncomment the following line
%disp('Angles');
h1 = subplot(3,1,1,'Parent',hTabs(3));
plot(h1,index,Tdata,'r','LineWidth',2);
hold on;
plot(h1,index,EKXdata,'b-','LineWidth',1);
hold off;
h2 = subplot(3,1,2,'Parent',hTabs(3));
plot(h2,index,Pdata,'r','LineWidth',2);
hold on;
plot(h2,index,EKYdata,'b-','LineWidth',1);
hold off;
h3 = subplot(3,1,3,'Parent',hTabs(3));
plot(h3,index,Ydata,'r','LineWidth',2);
end
完成启动合适的定时器!
答
关键是你想要使用的触发事件。如果您希望在选择第二个选项卡时自动更新它,则应该采取“选择第二个选项卡”的操作作为触发事件以更新图。