Plot data within a table and use categorial column to "split" them in the graph
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
the cyclist
le 2 Déc 2022
Modifié(e) : the cyclist
le 2 Déc 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.
Réponses (1)
Seth Furman
le 7 Déc 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 commentaires
Voir également
Catégories
En savoir plus sur Vector Fields dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!