how can i make a live data stream received and recorded from a sensor more time efficient?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Orel Levy
le 20 Août 2019
Réponse apportée : Ted Shultz
le 28 Août 2019
I am reading data from an IMU sensor and i am plotting it live by using:
"ax = subplot(m,n,iPlot);
linePlot = plot(ax, 0,[NaN NaN NaN]);"
and then:
for i=1:3
set(linePlot(i),'xData',t,'ydata',dataPlot(i,:));
end
where dataplot is a growing array which contains all data points received from the IMU.
I need to make the code more time efficient, and was wondering two things:
- how can i limit the plot to only show the last 500 points.
- is there a more efficient way to save the data from the sensor without having an always growing array of data? say is the a way to send the data to an outer struct and reset the parameter?
0 commentaires
Réponse acceptée
Ted Shultz
le 28 Août 2019
1) To only plot the last 500 points, you could plot use:
set(linePlot(i),'xData',t(end-500:end),'ydata',dataPlot(i,end-500:end));
2) Preallocating will make this a LOT faster. I don’t see how you are getting your data, but it looks like you have some function that adds a new point to the end of t and dataPlot. If that is the case, making these variables ahead of time and then just writing to an index would be much faster. Also if you wanted to only plot the most recent 500 points, you would use that index instead of “end”.
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!