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

2 views (last 30 days)
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
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.

Accepted Answer

Honglei Chen
Honglei Chen on 30 Jun 2016
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
Steven Lord
Steven Lord on 30 Jun 2016
From your description, animatedline may suit your needs as well.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!