question on timetable sorting loop

2 Ansichten (letzte 30 Tage)
slowlearner
slowlearner am 12 Mai 2020
Kommentiert: Shubh Sohal am 6 Okt. 2020
I have a litle project where i intend to see if there are any benefits of V2G in sweden just using some basic values for now. I have made this time table where I have 8760 rows with collumns such as [datetime spotprices] based on xlxs files posted on Nordpool, this is old data by the way. Now usually the spotprices are posted through an API a day ahead with 24h values, so in order to make my simulation somewhat realistic I turned the table in to seperate 24h cycle tables such as:
k = 1;
for mm = 1:24:8760-23 %rows to separate them by
Y{k} = A(mm:mm+23,:); %stor them in seperate Y{k} where k is 1:365
k = k+1;
end
s = reshape(Y,365,1);
clear k
Now seperatly I've just made some functions to calculate the charging and driving distances, but in order to make it more "smart" i guess i need to see which hour is the cheapest inorder to apply the V2G functions and make some profit hens the outer loop down below... At the moment i'm just doing a disp('') at the inner most loop to see if it all works as it should.
However coudn't make my break to work And if anyone has a better way to run this i'd appriciate the input. I'm still quite new just started with matlab a few weeks ago
i = 0;
g = 0;
q = 0;
for m = 1:1:365
bi = sortrows(s{m,1},'spotpris'); % sorts s{k} daily
C = bi(1:6,:); %defines the 6 cheapest hours of the day per day
D = bi(7:12,:); %defines the 6 2nd cheapest hours of the day per day
E = bi(13:18,:); %defines the 6 2nd most expensive hours of the day per day
F = bi(19:24,:); % defines the 6 most expensive hours of the day per day
g = g+1 %keep track of the day
for q = 1:1:24 %runs 1 iteration every hour up to 24th hour
i = i+1 %keep track of the hours
if ismember(A.tid(tid(i,1)),C{1,g}.tid) %== true
disp ('charge!')
elseif ismember(A.tid(tid(i,1)),D{1,g}.tid) %== true
disp('charge!!! maby if soc is needed?')
elseif ismember(A.tid(tid(i,1)),E{1,g}.tid) %== true
disp('charge only if soc is <0.3(to make trip home) OR discharge if soc is cool && batspotprise is good')
elseif ismember(A.tid(tid(i,1)),F{1,g}.tid) %== true
disp('only discharge if soc is cool && batspotpris is good')
else g>=2 && i>=48 %stop everything after 2 days
break
end
end
end
clear i j k m g
(edited)
  3 Kommentare
slowlearner
slowlearner am 15 Mai 2020
Bearbeitet: slowlearner am 15 Mai 2020
  • ill try putting the j loop in the outer one
  • havent gotten around to play with time yet
  • ah i see.. don't need the truths now it was just something that got stuck while constructing the statement
  • don't know this.. the inner needs to move hourly
  • I need the break to stop everything
thank you
Shubh Sohal
Shubh Sohal am 6 Okt. 2020
Along with the suggestions provided by @Sindar, it will definitely be helpful to take a look into the documentation reference for timerange.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by