- the 'j' loop only has one iteration: j=1.
- timerange is a more reliable method of accessing periods than indexing
- why use "if x == true" syntax? "if x" works the same
- You can probably avoid the q loop altogether by returning a second argument from sortrows
- m=g=k+1
- The break will only exit the q loop; is that what you want?
question on timetable sorting loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Shubh Sohal
el 6 de Oct. de 2020
Along with the suggestions provided by @Sindar, it will definitely be helpful to take a look into the documentation reference for timerange.
Respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!