How to plot two data set with two different durations in the same plot?
Show older comments
I have two datasets of electric load created by EVs, but each has different ending times, but the values remain the same. So second one, when I plot should be more flat. How do I plot two datasets with different durations in the same plot? Example data is attached.
StackOverflowEx = convertvars(StackOverflowEx, {'st_time', 'end_time'}, 'string');
st_time = StackOverflowEx.st_time;
end_time = StackOverflowEx.end_time;
value = StackOverflowEx.PevrReal; % calculated value from excel to distribute
% evenly over the interval time
timediff = StackOverflowEx.tchmin; % time of end and start time difference in minutes
singularvalue = value./timediff;
singularvalue(~isfinite(singularvalue)) = 0;% value per hour
Tzeros_LSH = zeros(24*60+1,1); % from 1 to 1440 scale is created to simulate day
% in minutes (+1 is for to avoid 0 values in
% time)
traffic_DCH = zeros(24*60+1,1); % scale for creating traffic (Discharging potential or Load shifting in this case)
%% 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_DCH(TrSt:TrEn,1) = Tzeros_LSH(TrSt:TrEn,1) + 1;
traffic_DCH(TrSt:TrEn,1) = traffic_DCH(TrSt:TrEn,1) + singularvalue(i); % adding
% singular values
end
end
%% TIME AXIS
close all
TimeM = 1:length(Tzeros_LSH);
TimeH = TimeM/60;
%% PLOT(TimeH,T2 ,TimeH)
figure
plot(TimeH,traffic_DCH)
xlim([1 24])
xlabel("Time (h)")
ylabel("Load (kW)")
grid on
Since the values are the same, I have added second ending time as "end_time2", and this code I was using for plotting only the first one. I couldn't figure out how to add second one to plot in the same graph. Also, my data is almost one million entries and it's taking too long time to execute. Maybe there is more efficient ways to do so? Thanks beforehand.
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!