How to use set() to put multiple y-data points on plot

7 次查看(过去 30 天)
Hello,
I am working on a project that displays live data from a load cell on a matlab plot, so the user can see whether or not the equipment is functioning properly. I need to show six sets of y-data across the same time span all on the same plot. I tried using the standard 'hold on' with plot(data(:,ii)) in a for loop, but this is just too slow. From what I've been reading, the set() command will work wonders (and already has), but I'm having trouble getting all of the data on the plot at once. What I have right now is something like this.
data=[force and time data in here] (500x7 matrix)
plotdata=plot(nan) used to create a plot with nothing in it so far
for ii=1:length(data)-1
set(plotdata,'XData',data(:,end),'YData',data(:,ii))
drawnow
end
As I loop through, the plot will update with the data in whichever column the loop is on, but on the next iteration it goes away and the new data shows. I tried using hold on but this was no help. Is there any way to keep all of the data on the plot using the set() command? I let the code run for almost 10 minutes and there wasn't even a hint of it slowing down, so I am confident this method will work, I just need to figure out how to get everything to stay on the plot. Thanks for your help.
Carmelo

采纳的回答

Honglei Chen
Honglei Chen 2016-6-30
Do you know the size of data? If so, you can do something like
x = [rand(100,6) (1:100)']; % 100x7 matrix
plotdata = plot(x(:,end),nan(100,6));
for m = 1:6
set(plotdata(m),'YData',x(:,m));
drawnow;
end
HTH
  2 个评论
Carmelo Gonzales
Carmelo Gonzales 2016-6-30
I do know the size of the data, and this works! Thank you for the quick help.
Steven Lord
Steven Lord 2016-6-30
From your description, animatedline may suit your needs as well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by