Plotting data at a fast rate in app designer

22 views (last 30 days)
Juha Forssell
Juha Forssell on 17 May 2021
Answered: Mohammad Sami on 18 May 2021
Hey,
I have been trying to use app designer to plot data from a file. The file's data is originally collected with a 50 Hz sample rate. Is it at all possible to plot the data this fast in app designer. In the code I have now the frequency of the plotting can be changed by changing the period in the timer object creation. However, my computer struggles to plot the data even at a 0.5 second rate. Is there any way of plotting the data in a different way that allows for a faster frequency? So my code works, but it really isn't useful if I cannot plot at a higher frequency. There might be some parts in the code that are redundant such as the variable z, but you can ignore those.
All (hopefully) relevant parts of the code below.
properties (Access = private)
aTimer%计时器对象
A
ii
end
methods (Access = private)
功能atimerfcn(应用程序,〜,事件)
% get current time from timer's event data
tnow = datetime(event.Data.time);
app.ii = app.ii+1;
A1 = app.A(app.ii,:);
matrix = reshape(A1,[4,4]);
y = rand();
z = y+1;
%cdata = rand(4,4);
%data = rand(1,8);
% Plot data and adjust XLim if current time is out of bounds
xll = app.uiaxes.xlim(1);
xUL = app.UIAxes.XLim(2);
if(tnow > xUL)
xtra = seconds(15);
app.UIAxes.XLim = [xLL+xtra tnow+xtra];
app.UIAxes.XTick = linspace(xLL+xtra, tnow+xtra, 5);
end
情节(app.uiaxes,tnow,a1,'linestyle',"-",“标记”,“。”);%, tnow, z, 'oy');
heatmap(app.MatrixPanel, matrix,'Colormap',parula,'CellLabelColor','none','ColorLimits',[410 420]);
%调整Ylim以更好地显示变化
yll = 400;%max(y-5, 0);
yUL = 430;%y + 5;
app.UIAxes.YLim = [yLL yUL];
%app.uiaxes.ytick = round(linspace(YLL,YUL,5),2,“显着”);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
功能startupfcn(app)
app.AAUIFigure.Name ='AA项目v0.1 01apr21';
% Plot invisible data point to initialize datetime ruler
绘图(app.uiaxes,dateTime('now'), 50岁,'ob');
cdata = rand(8,8);
app.a = readmatrix('A.txt','FileType','文本');
热图(app.matrixpanel,cdata);
% Set x limits and ticks
t = dateTime('now') +秒(1:60);
app.ii = 0;
xLL = t(1) - seconds(5);
xUL = t(length(t));
app.UIAxes.XLim = [xLL xUL];
app.uiaxes.xaxis.ticklabelformat ='hh:mm:ss';
app.UIAxes.XTick = linspace(xLL, xUL, 5);
% Set y limits and ticks
app.UIAxes.YLim = [0 50];
app.UIAxes.YTick = round(linspace(0, 50, 5), 2,'重要的');
网格(app.uiaxes,'on');
hold(app.UIAxes,'on');
%创建计时器对象
app.aTimer = timer(...
'ExecutionMode','fixedRate',...% Run timer repeatedly
'Period', 1,...% Period is 1 second
'BusyMode','queue',...% Queue timer callbacks when busy
'TimerFcn', @app.aTimerFcn);% Callback that runs every period
end

Answers (1)

Mohammad Sami
Mohammad Sami on 18 May 2021
类似于您在应用程序属性中存储UIAXES的方式,您还需要存储剧情和热图中的热图。然后,您可以在计时器功能中更新它们。那应该加快您的代码。
properties (Access = private)
aTimer%计时器对象
A
ii
dataplot
Heatmapplot
end
功能startupfcn(app)
%....%
app.heatmapplot = heatmap(app.MatrixPanel, cdata,'Colormap',parula,'CellLabelColor','none','ColorLimits',[410 420]);
%....%
app.dataplot = plot(app.uiaxes,dateTime('now'), 50岁,'linestyle',"-",“标记”,“。”);
%....%
end
然后,在计时器函数中,您可以直接更新地图和图。
功能atimerfcn(应用程序,〜,事件)
%....%
app.heatmapplot.ColorData = matrix;
%....%
app.dataplot.XData = tnow;
app.dataplot.YData = A1;
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

开始狩猎!