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!