How do you change the X-axis to update in real time on a plot in a live data acquisition GUI?
4 次查看(过去 30 天)
显示 更早的评论
I am working on a GUI with several plots showing data acquired in real time. Plot 1 (attached below) starts with a small range on the x-axis. Then, during the three seconds of data acquisition, the axis grows as the data is plotted to reach a range from 0 to 3 seconds. Plot 2 (also attached below) starts with a range from 0 to 0.1 seconds. During data acquisition, Plot 2 moves through the 3 seconds in 0.1 second increments, from 0 to 0.1 all the way until it reaches 2.9 to 3.0 seconds. I would like Plot 2 to behave the same way as Plot 1, starting with a small range which then expands as data is acquired to show the full range from 0 to 3 seconds. I am having trouble because the code I use to generate these plots is almost identical.
Here is the code:
s = daq.createSession('ni');
ch = addAnalogInputChannel(s, 'Dev1', 0:2, 'Voltage');
ch(1).TerminalConfig = 'SingleEnded';ch(2).TerminalConfig = 'SingleEnded';
s.DurationInSeconds = 3;
s.Rate = 1000;
dataListener1 = addlistener(s, 'DataAvailable', @(src, event) datamanager(src, event));
startBackground(s)
hGui.Fig = figure('Name','Live GUI', ...
'NumberTitle', 'off', 'Resize', 'on', 'Position', [10 50 1900 950]);
%Code for Plot 1
hGui.Axes1 = axes;
set(hGui.Axes1, 'Units', 'Pixels', 'Position', [200 200 450 100]);
%Code for Plot 2
hGui.Axes2 = axes;
set(hGui.Axes2, 'Units', 'Pixels', 'Position', [200 50 450 100]);
function datamanager(src, event, varargin)
hGui.DataPlot1=plot(hGui.Axes1, event.TimeStamps, event.Data(:,1),'.k') ; hold on
hGui.DataPlot2=plot(hGui.Axes2, event.TimeStamps, event.Data(:,2),'.k') ; hold on
end
One thing that happens is when I comment out the Code for Plot 1, Plot 1 disappears and Plot 2 works as I want it to, starting with a small range and expanding as data is acquired to show the full 0 to 3 seconds range. I'm not sure why that is. Any insight on how to get Plot 2 to work like Plot 1 would be great. Thanks!
0 个评论
采纳的回答
Geoff Hayes
2016-9-29
Eamon - perhaps the hold isn't being applied to the second axes when both are being updated. Try being explicit about which axes you want to apply the hold to. For example,
hold(hGui.Axes1 ,'on');
hold(hGui.Axes2 ,'on');
instead of the
hold on;
in your above code.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Visual Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!