How to make a line-plot? Time series
Afficher commentaires plus anciens
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 commentaires
Les Beckham
le 8 Fév 2023
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
le 9 Fév 2023
Réponse acceptée
Plus de réponses (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
Catégories
En savoir plus sur Axes Appearance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



