Plot data within a table and use categorial column to "split" them in the graph
8 views (last 30 days)
Show older comments
Hello guys,
I have a table.
The size is 795183x35 (in the original data).
The column 3 "RotorNumber" is type categorial.
How can I plot (it doesn´t matter which plot but e.g. quiver) the data of the other rows but by considering the categories so i can have a legend with the different categories?
My first idea was to make a for-loop and to split the table by comparing the categorial data... but for sure there is a much easier way..??
I never worked with categorial data so I don´t know how to handle these... .
Best regards...
and thanks in advance.
2 Comments
the cyclist
on 2 Dec 2022
Edited: the cyclist
on 2 Dec 2022
This would be easier to help with if you posted a small sample of the table (e.g. maybe 10 rows, with a few different categories of RotorNumber). You can used the paper clip icon in the INSERT section of the toolbar to upload it here.
Answers (1)
Seth Furman
on 7 Dec 2022
Group data by RotorNumber using findgroups
load MiniExample.mat
t = sortrows(ExampleTable)
[groupNums,uniqueRotorNumbers] = findgroups(t.RotorNumber)
Plot data using splitapply and plot
hold on
splitapply(@plot,t(:,"b"),groupNums)
hold off
legend(string(uniqueRotorNumbers));
title("b vs. Row Number");
ylabel("b");
xlabel("Row Number");
figure
hold on
splitapply(@(x,y)plot(x,y),t(:,["datetime","b"]),groupNums)
hold off
legend(string(uniqueRotorNumbers));
title("b vs. datetime");
ylabel("b");
xlabel("datetime");
Plot data using splitapply and stackedplot support for multiple table inputs
tableCellData2Table = @(varargin){table(varargin{:},VariableNames=t.Properties.VariableNames)};
tCell = splitapply(tableCellData2Table,t,groupNums)
variablesToPlot = t.Properties.VariableNames(5:6);
stackedplot(tCell,variablesToPlot,LegendLabels=string(uniqueRotorNumbers))
OR you can set the x-variable with the XVariable parameter.
stackedplot(tCell,variablesToPlot,LegendLabels=string(uniqueRotorNumbers),XVariable="datetime")
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!