I am trying to generate graph of traffic by each occupation group of car users. So far, I can produce overall traffic with the code below:
load('driving_profiletest.mat');drivingprofiletest.end_time(strcmp(drivingprofiletest.end_time,'00:00')) = {'23:59'};drivingprofiletest = convertvars(drivingprofiletest, {'st_time', 'end_time'}, 'string');%% DATA VARIABLES
ev_id = drivingprofiletest.hp_id;distance = drivingprofiletest.distance;realdistance = drivingprofiletest.realdistance;st_time = drivingprofiletest.st_time;end_time = drivingprofiletest.end_time;occupation = drivingprofiletest.occupation;housing = drivingprofiletest.housing;carsize = drivingprofiletest.car_size;state = drivingprofiletest.state;regiostar = drivingprofiletest.regiostarGem7;% select value(s) to be analyzed
value = drivingprofiletest.realdistance;%DURATION OF PARKING AND DRIVING
t_End = datetime(drivingprofiletest.end_time,'InputFormat','HH:mm');t_St = datetime(drivingprofiletest.st_time,'InputFormat','HH:mm');tt_End = hour(t_End) + minute(t_End)/60;tt_St = hour(t_St) + minute(t_St)/60;drivingprofiletest.duration = tt_End - tt_St;duration = drivingprofiletest.duration;timediff = duration.*60; singularvalue = value./timediff;Tzeros_LSH = zeros(24*60+1,1);traffic = zeros(24*60+1,1);%% INTERVAL SPREAD
for i = 1:length(end_time) [Y, M, D, H, MN, S] = datevec(st_time(i)); TrSt = H*60+MN+1; [Y, M, D, H, MN, S] = datevec(end_time(i)); TrEn = H*60+MN+1; if isnan(TrEn) || isnan(TrSt) continue else Tzeros_LSH(TrSt:TrEn,1) = Tzeros_LSH(TrSt:TrEn,1) + 1; traffic(TrSt:TrEn,1) = traffic(TrSt:TrEn,1) + singularvalue(i); endend%% TIME AXIS
close allt_min = 1:length(Tzeros_LSH);t_hour = t_min/60;%T2 = Tzeros./max(Tzeros);
%VelMat2 = VelMat./max(VelMat);
%% PLOTTING
figureplot(t_hour,traffic)xlim([1 24])xlabel("Time (h)")ylabel("Load shifting potential (kW)")%ylabel("Load shifting potential (kW)") % label variable
grid on
I don't know if my brain stopped working now, but is there any way to generate graph in the same plot, but for each occupational category and without extracting each unique category, because later I wan to do the same with States, car_size etc?. For example: for full-time is one line, for pensioners is another etc. Thanks for the help beforehand. (data used is attached)
Best Answer