How to speed of execution in my code?
    7 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposte (1)
  Sourabh Kondapaka
    
 il 18 Set 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)
0 Commenti
Vedere anche
Categorie
				Scopri di più su Annotations in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

