how do i get the average line graph
Afficher commentaires plus anciens
Hello! i am quite new to matlab here! been stuck on this problem for a few days now, but here is my code. Basically i have a folder with mutiple excel file each filled with data. i am trying to get the plot the average line graph only.
%loop through selected ".xls" files
[file_list,path_n]=uigetfile(".xls","Grab files fo half hourly demand",'Multiselect','on');
if iscell(file_list)==0
file_list={file_list};
end
%call function
plotdata = selecteddata(path_n,file_list);
%function
function plotdata = selecteddata(path_n, file_list)
Months = ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"];
for k= 1:length(Months)
Months_idx = contains(file_list, Months(k));
B =[file_list(Months_idx)];
plotdata=figure;
for i=1:length(B)
filename=B{i};
data_in=xlsread([path_n filename]);
mon=data_in(:,1);
tue=data_in(:,4);
wed=data_in(:,7);
thur=data_in(:,10);
fri=data_in(:,13);
sat=data_in(:,16);
sun=data_in(:,19);
time = hours(0.5): hours(0.5):hours(24);
hold on
plot(time,mon,time,tue,time,wed,time,thur,time,fri,time,sat,time,sun)
legend('mon','tue','wed','thur','fri','sat','sun')
title(B)
end
end
end
Currently this is the output. Help would be greatly appreicated!

Réponses (1)
Star Strider
le 2 Oct 2021
I do not have your data, however since they all have the same number of elements as ‘time’ and so can be assumed to be equal length vectors, one option would be —
alldays{k,i} = cat(2, mon,tue,wed,thur,fri,sat,sun);
I would put that just before the ‘time’ assignment. Calculate and plot the mean (and perhaps other) values across dimension 2 at the appropriate place in your code.
I am not certain what the code does, so it may be necessary to change the cell array subscript to produce the desired result.
.
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!