Plot data within a table and use categorial column to "split" them in the graph
7 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
the cyclist
2022 年 12 月 2 日
編集済み: the cyclist
2022 年 12 月 2 日
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.
回答 (1 件)
Seth Furman
2022 年 12 月 7 日
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 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!