How to speed of execution in my code?

2 views (last 30 days)
Asrorkhuja Ortikov
Asrorkhuja Ortikov on 15 Sep 2020
Answered: Sourabh Kondapaka on 18 Sep 2020
I have a code to plot about million entries, and with my code it's taking too long time. I don't how to improve speed up the execution. Can anybody help?The data unforetunately cannot be attached.
load('UncontrolledChargingHHincluded.mat')
UncontrolledChargingHHincluded = convertvars(UncontrolledChargingHHincluded, {'st_time', 'end_time'}, 'string');
%% VARIABLES
st_time = UncontrolledChargingHHincluded.st_time;
end_time = UncontrolledChargingHHincluded.end_time;
value = UncontrolledChargingHHincluded.PevHH; % calculated value from excel to distribute
% evenly over the interval time
timediff = UncontrolledChargingHHincluded.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)
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

Answers (1)

Sourabh Kondapaka
Sourabh Kondapaka on 18 Sep 2020
Hi,
I explained how to speed up your code here.(this is another question you had asked on how to plot for end_time2 on the same figure)

Categories

Find more on Dates and Time 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!