Day of Week data plot
Afficher commentaires plus anciens
Hi, I need to plot daily element concentration averages by day of week (using several months of data). The code I've included does work (I've also included an image of the plot output), but since we measure so many species I'd like to include some kind of for loop to make the process quicker and be able to plot more elements at a time without so much individual specification. Our instrument output gives us concentration and uncertainty columns for each element. Would love any input on this - relatively new to Matlab/coding. Thanks!
Dayofweek = weekday(Xactdata.Date(Data));
Sun = find(Dayofweek == 1); Mon = find(Dayofweek == 2); Tue = find(Dayofweek == 3); Wed = find(Dayofweek == 4); Thu = find(Dayofweek == 5); Fri = find(Dayofweek == 6); Sat = find(Dayofweek == 7);
wk = [1 2 3 4 5 6 7];
S_wk = [Xactdata.SULPHUR(Data)];
S_wk_err = [Xactdata.S_U(Data)];
Cl_wk = [Xactdata.CHLORINE(Data)];
Cl_wk_err = [Xactdata.Cl_U(Data)];
Xact_week_Cl = [mean(Cl_wk(Sun)) mean(Cl_wk(Mon)) mean(Cl_wk(Tue)) mean(Cl_wk(Wed)) mean(Cl_wk(Thu)) mean(Cl_wk(Fri)) mean(Cl_wk(Sat))];
Xact_err_week_Cl = [mean(Cl_wk_err(Sun)) mean(Cl_wk_err(Mon)) mean(Cl_wk_err(Tue)) mean(Cl_wk_err(Wed)) mean(Cl_wk_err(Thu)) mean(Cl_wk_err(Fri)) mean(Cl_wk_err(Sat))];
Xact_week_S = [mean(S_wk(Sun)) mean(S_wk(Mon)) mean(S_wk(Tue)) mean(S_wk(Wed)) mean(S_wk(Thu)) mean(S_wk(Fri)) mean(S_wk(Sat))];
Xact_err_week_S = [mean(S_wk_err(Sun)) mean(S_wk_err(Mon)) mean(S_wk_err(Tue)) mean(S_wk_err(Wed)) mean(S_wk_err(Thu)) mean(S_wk_err(Fri)) mean(S_wk_err(Sat))];
figure
errorbar(wk, Xact_week_S, Xact_err_week_S)
hold on
errorbar(wk, Xact_week_Cl, Xact_err_week_Cl)
xticklabels({'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'})
title('Weekly Concentrations'); %Modify as needed
legend('S', 'Cl')
ylabel('Concentration (ng/m^3)');

Réponse acceptée
Plus de réponses (1)
Image Analyst
le 16 Déc 2023
0 votes
They will do functions, like mean, based on what group the data is in.
Catégories
En savoir plus sur Polar Plots 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!


