Conditioning MATLAB to move daytime -> nighttime and then execute a command

1 次查看(过去 30 天)
Hi!
I have a system with solar panels, a machine and a battery. I have the solar energy input as hourly data, which I have also summed to form daily data (for one year).
Once the machine reaches maximum capacity (during the day), excess solar energy is stored in the battery. This battery is then used to run the machine when outside energy input is zero (nighttime). Both cannot be run at the same time, so battery = 1 when solar input = 0.
But I cannot figure out how to limit my battery usage & production to when it is nighttime, and that it does not exceed the energy available in the battery.
I tried to recreate my problem here in a smaller scale. Xexcess is the same as my two-day solar input in June.
Batterycapacity = 600 ;% kWh
Machineinput = 4.9 ;% kWh per 1 product required by the machine
Machinemax = 80 ;% Maximum products in one hour
at_least = 0 ;
at_most = Machinemax ;
% Production = # of products * Machineinput
% Xexcess = SolarEnergy - Production
% Excess energy after running the machine during the day
Xexcess = [0 ;0 ;0;0;0;73.39700;503.651000000000;1298.33275000000;1947.20675000000;2558.90575000000;3060.62125000000;3426.68525000000;3654.41450000000;3680.47475000000;3533.69175000000;3213.53500000000;2697.41400000000;2066.83475000000;1420.55350000000;776.354250000000;154.095000000000;0;0;0;0;0;0;0;0;51.1245000000000;356.777250000000;886.828250000000;1154.03675000000;1473.29450000000;2135.04750000000;2566.19700000000;2361.74800000000;1824.94775000000;1695.84975000000;1442.71375000000;901.706500000000;459.097250000000;125.444750000000;45.4517500000000;22.5202500000000;0;0;0;]
Xexcess(Xexcess > Batterycapacity) = Batterycapacity ;
% # of products that can be manufactured with battery energy
Y = min(max((Xexcess/Machineinput),at_least),at_most);
Now as you can see there is plenty of excess electricity left during the day. But instead of running simultaneously, the battery can only be used during that 8-hour window of zeros you see in the matrix. So Y shown here is much larger than possible.
This time-window varies during the year, it can be longer or shorter, but the point is this is where the battery can be used.
Is there a way to condition MATLAB to somehow take my Xexcess, move it to when SolarEnergy &/ Xexcess = 0, and then calculate Y? And then stop calculating this once the battery is depleted or when SolarEnergy = 1 again (sunrise)?
I am not experienced with the program so while I know the existence of if & for loops, I dont know how to sufficiently use them. So I guess I need a loop that somehow subtracts the used excess from the battery capacity, so the machine only runs during the night while the battery still has energy left?
I would appreciate any help, and if you need any more details let me know I will try to describe it better.
-Tarmo

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by