question on timetable sorting loop

조회 수: 4 (최근 30일)
slowlearner
slowlearner 2020년 5월 12일
댓글: Shubh Sohal 2020년 10월 6일
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
slowlearner
slowlearner 2020년 5월 15일
편집: slowlearner 2020년 5월 15일
  • 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 2020년 10월 6일
Along with the suggestions provided by @Sindar, it will definitely be helpful to take a look into the documentation reference for timerange.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by