how can i rectify index position error?

Hi guys,
Thanks for your support so far, please this part of matlab script (hydrogen storage model) is given me this error:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in mescode2019 (line 264)
mesprob.Constraints.hydeogenstored=selfdchh*Eh2(idxHr2Toend-1,:)+(echh2*(h2ch(idxHr2Toend,:)*dt))-((edchh2(idxHr2Toend,:)*dt)/edh2)==Eh2(idxHr2Toend,:);
%initial time variables for 24hrs
dt=1; % Time step
nHours=numel(LD);
Time=(1:nHours)';
idxHr2Toend=2:nHours;
%battery model
mesprob.Constraints.Batstoredele=selfdchb*Et(idxHr2Toend-1,:)+(echb.*Pbch(idxHr2Toend,:)*dt)-...
((Pbdch(idxHr2Toend,:)*dt)./edchb)==Et(idxHr2Toend,:);
mesprob.Constraints.SOCb=Et(idxHr2Toend(1),:)<=Et(idxHr2Toend(end),:);
mesprob.Constraints.Etout=Et<= NOMb;
%thermal storage model
mesprob.Constraints.thermalstored=(1-qselfdch)*Eq(idxHr2Toend-1,:)+(echq.*(qch(idxHr2Toend,:)*dt))-...
((qdch(idxHr2Toend,:)*dt)./edchq)==Eq(idxHr2Toend,:);
mesprob.Constraints.SOCq=Eq(idxHr2Toend(1),:)<=Eq(idxHr2Toend(end),:);
mesprob.Constraints.Eqout=Eq<= NOMq;
%cold storage model
mesprob.Constraints.coldstored=(1-cselfdch)*Ec(idxHr2Toend-1,:)+(echc.*(cch(idxHr2Toend,:)*dt))...
-((cdch(idxHr2Toend,:)*dt)./edchc)==Ec(idxHr2Toend,:);
mesprob.Constraints.SOCc=Ec(idxHr2Toend(1),:)<=Ec(idxHr2Toend(end),:);
mesprob.Constraints.Ecout=Ec<= NOMc;
%hydrogen storage model
mesprob.Constraints.hydeogenstored=selfdchh*Eh2(idxHr2Toend-1,:)+(echh2*(h2ch(idxHr2Toend,:)*dt))...
-((edchh2(idxHr2Toend,:)*dt)/edh2)==Eh2(idxHr2Toend,:);
mesprob.Constraints.SOCh=Eh2(idxHr2Toend(1),:)<=Eh2(idxHr2Toend(end),:);
mesprob.Constraints.Ehout=Eh2 <= NOMh;
This most confusing part is that, the same procedure is applicable to battery storage, cold storage and heat storage, but those ones are not showing that kind of error, please how can i rectify it?
Thanks

8 comentarios

Walter Roberson
Walter Roberson el 23 de En. de 2020
As outsiders, we do not know the size of any of those variables.
tobi alabi
tobi alabi el 23 de En. de 2020
thank you walter for the response,
most of the variables are scalars while LD is 24 rows( each hour energy demand in a day)
Walter Roberson
Walter Roberson el 23 de En. de 2020
You try to access multiple rows of several different variables. Scalars only have one row.
tobi alabi
tobi alabi el 24 de En. de 2020
@walter, please how can i correct it? because i did similar things to the other storage model and they did not indicate error?
KALYAN ACHARJYA
KALYAN ACHARJYA el 24 de En. de 2020
Hello Tobi,
Without getting the details of data and variabes, I cant say that "this parameter" exceed the its array length. But you can easily find it by exmine the sizes of variables from the error line. May be you are trying to access some variables, which doesnot have that enough length/size.
Walter Roberson
Walter Roberson el 24 de En. de 2020
As I scan the code it looks to me as if it could only work if LD had exactly one element, and the result it would produce would be empty. If LD is 2 or more elements then the code would try to access row 2 of a number of variables that you have told us are scalars.
% Load all the datas
LD=[0.1 0.5 0.4 3 5 3 3.5 0.1 0.1 1 3 2 2.3 2.3 2 2.5 5 6 7 6.5...
4 2.5 2.3 0.1]; % Home Load Data for 24 hrs in kW
%initial time variables for 24hrs
dt=1; % Time step
nHours=numel(LD);
Time=(1:nHours)';
idxHr2Toend=2:nHours;
%hydrogen storage model
selfdchh=0.001; %self-discharging parameters
Eh2=optimvar('Eh2',nHours,1,'LowerBound',0,'UpperBound',20` );
mesprob.Constraints.hydeogenstored=selfdchh*Eh2(idxHr2Toend-1,:)+(echh2*(h2ch(idxHr2Toend,:)*dt))...
-((edchh2(idxHr2Toend,:)*dt)/edh2)==Eh2(idxHr2Toend,:);
mesprob.Constraints.SOCh=Eh2(idxHr2Toend(1),:)<=Eh2(idxHr2Toend(end),:);
mesprob.Constraints.Ehout=Eh2 <= NOMh;
the information are the details concerning the code, if i change idxHr2Toend=2:nHours to 1:nHours, it will display error concerning the matrix agreement
tobi alabi
tobi alabi el 24 de En. de 2020
Thank you very much everyone, i've been able to rectify the error

Respuestas (0)

La pregunta está cerrada.

Productos

Etiquetas

Preguntada:

el 23 de En. de 2020

Cerrada:

el 2 de Oct. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by