sizing microgrid using for and if statement
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am currently doing a project where my task is to size the components in micro-grid and calculate the LCC. I extracted the data för one day. Data I have are: Battery voltage, Battery current, Inverter power( reprecent the consumption), Solar power (represent the production).I am a beginner in matlab and hope that some one can help me here. I want to write a code that loop through all the hours in the day and calculate the following:
for all hours
if (production > consumption) and (battery power <= 80%*Battery max capacity)
charge the battery= Production-consumption
elseif (production > consumption) and (battery power >= 80%*Battery max capacity)
wasted power= Production-consumption
elseif (consumption > production) and (battery power >= 20%*Battery max capacity)
use the battery=consumption-production
else (consumption > production) and (battery power <= 20%*Battery max capacity)
increase battery capacity = consumption-production
end
I am already stuck by looping through all the hours and dont know how to do it
so thankful for help
댓글 수: 1
Guillaume
2019년 4월 24일
In all likelyhood you don't need a loop. Your test can probably be carried out at once on all the data.
For us to be able to give you an answer that works for you, it would be very useful to see an example of the data (is it a table, cell array, one or more matrix? How is the time stored? As a datetime? datenum? datestr?, etc.). So please attach a demo mat file to your question.
채택된 답변
Guillaume
2019년 4월 25일
It sounds like you have several problems. The first one being the data generation which you currently do with some form of digitisation. I don't think it's something I can help with. Then you have the problem of processing your data once you've generated it.
I don't really understand what you're doing with your datenum, datevec, datestr. One thing for sure, it probably doesn't do what you want since at one point you're using hours/minutes/seconds in place of year/month/day. In any case, you shouldn't be using any of these types. Use datetime which is so much more practical. E.g. if you want to generate dates in a day in interval of 1 minutes:
d = datetime('2019-03-30 00:00:00') + minutes(0:24*60-1);
solardata = timetable(sometimevector, B_v(:), P_s(:), P_inv(:), 'VariableNames', {'BatteryVoltage', 'SolarPower', 'InverterPower'});
After that you can store the state of your system (I think that's what you want to do, it's not clear) in a new column, eg.:
solardata.State(solardata.SolarPower > solardata.InverterPower & solardata.BatteryVoltage <= 0.8*SOCmax) = "charging";
solardata.State(solardata.SolarPower > solardata.InverterPower & solardata.BatteryVoltage > 0.8*SOCmax) = "wasting power";
solardata.State(solardata.SolarPower <= solardata.InverterPower & solardata.BatteryVoltage >= 0.2*SOCmax) = "discharging";
solardata.State(solardata.SolarPower <= solardata.InverterPower & solardata.BatteryVoltage < 0.2*SOCmax) = "low battery";
댓글 수: 3
Guillaume
2019년 4월 30일
That last error you get is because the Time is not considered a variable in a timetable and therefore you should only specify four variable names.
Summer_week_data=timetable(interpt(:),interpBat_V(:),interpBat_C(:),interpSol_p(:),interpInv_P(:),'VariableNames',{Battery_volt','Battery_current','Solar_power','Inverter_power'});
It seems you have figured out how to resolve your different length issue.
Guillaume
2019년 4월 30일
편집: Guillaume
2019년 4월 30일
Please comment on the answer rather than starting new answers.
I thought the way you interpolated your data was fine, so I'm not sure why you're no longer doing that. Another option is to start with one timetable per variable and then synchronize them all. Since all your variables have the same duration, create one timetable per variable with a linspace'd time vector:
starttime = datetime(2018,07,01,14,0,0);
endtime = datetime(2018,07,05,14,0,0);
tVbat = timetable(linspace(starttime, endtime, numel(Bat_V)', Bat_V, 'VariableNames', {'Battery_volt'}))
tCbat = timetable(linspace(starttime, endtime, numel(Bat_C)', Bat_C, 'VariableNames', {'Battery_current'}))
tbat = synchronize(tVbat, tCbat, 'Uniform', 'Interval', minutes(1));
%... etc for other variables.
추가 답변 (1개)
Abm
2019년 4월 30일
Thank you so much for responding !! I kept thinking in this problem from yesterday.
I will continue as you suggest for the rest of the solution.
Best regards
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!