How to make a line-plot? Time series
古いコメントを表示
Hi there, simple question. This is a subset of a larger dataset. How do I make a lineplot of the schoolyear 2000 and 2002 "students" time series? It should be one plot with two lines.
Thank you.
clc;
close all;
clear all;
table_a = readtable('Data1.xlsx');
for i = 1:height(table_a)
if table_a.month(i)>=8
schoolyear(i) = table_a.year(i) + 1;
else
schoolyear(i) = table_a.year(i);
end
end
table_a.schoolyear = schoolyear(:)
2 件のコメント
Les Beckham
2023 年 2 月 8 日
What did you try?
You probably need to decide what you want to plot the selected students data against. In other words, if the selected students data is to be on the y axis of the plot, what goes on the x axis?
Macy
2023 年 2 月 9 日
採用された回答
その他の回答 (1 件)
Here is one of the possible solution codes:
table_a = readtable('Data1.xlsx');
table_a.schoolyear = table_a.year;
table_a.schoolyear(table_a.month>=8) = table_a.year(table_a.month>=8)+1;
figure
yyaxis left
plot(1:height(table_a),table_a.students, 'bo-', 'LineWidth',2)
ylabel('# of students')
ylim([min(table_a.students)-1, max(table_a.students)+1])
yyaxis right
plot(1:height(table_a), table_a.schoolyear, 'rd--', 'LineWidth',2)
yticks([ 2000 2001 2002 ])
yticklabels({ '2000','2001','2002' })
ylim([1999 2003])
ylabel('School year')
grid on
カテゴリ
ヘルプ センター および File Exchange で Time Series Events についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



