Plotting data in table after grouping

5 views (last 30 days)
I'm trying to plot data in a table after grouping it. If possible, I'd like to avoid using for loops with repeated 'plot' calls, since I think it would be slow. See below for an example of what I'm trying to do. Is there a way to make this code more efficient (e.g., avoid using for loops, or make a single 'plot' call)?
Thank you,
tbl = table([1;1;1;2;2;2;2;3;3],[0;1;4;0;2;3;5;1;4],rand(9,1),'VariableNames',{'id','t','x'});
uniqueIDs = unique(;
hold on;
for iID = 1:length(uniqueIDs)
t = tbl.t(;
x = tbl.x(;

Accepted Answer

Adam Danz
Adam Danz on 3 Jan 2020
Edited: Adam Danz on 6 Jan 2020
arrayfun() is one way to do that.
tbl = table([1;1;1;2;2;2;2;3;3],[0;1;4;0;2;3;5;1;4],rand(9,1),'VariableNames',{'id','t','x'});
hold on
arrayfun(@(i)plot(tbl.t(,tbl.x(,unique( % do plotting

More Answers (0)

Community Treasure Hunt

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

Start Hunting!