How to speed of execution in my code?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Sourabh Kondapaka
2020년 9월 18일
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!