Effacer les filtres
Effacer les filtres

Array indices must be positive integers or logical values

3 vues (au cours des 30 derniers jours)
Fabian Haslwanter
Fabian Haslwanter le 16 Jan 2023
Commenté : Walter Roberson le 16 Jan 2023
So i have the following Constraints for a heat storage (ws) as part of my yalmip optimization problem:
Constraints=[]
for t = 1:24
Constraints = [Constraints, dE(t) <= dEmax_WS, E_ws(t) <= Emax_ws, E_ws(t) == E_ws(t-1)+dE(t), E_ws(0) == 10];
end
When running, i get an indexing error:
"Error using sdpvar/subsref (line 161) -Array indices must be positive integers or logical values."
I assume the problem is the last equation, which should determine the current state of charge by adding the charge rate to the charge of the previous time step.
I know one way to change this is to start the loop at t=2 and define E_ws(1)=10. Is there another smoother way which lets me keep the equation in the same loop as the "regular" constraints?
Thank you!

Réponse acceptée

KSSV
KSSV le 16 Jan 2023
This line:
E_ws(0) == 10
gives you error. MATLAB indexing starts from 1. It cannot be zero. Think of it.
  4 commentaires
Fabian Haslwanter
Fabian Haslwanter le 16 Jan 2023
I tried this as well, but I am still getting the same error:
clear all
%Constraints
Constraints=[];
for t = 1:24
Constraints = [Constraints, dE(t) <= dEmax_ws, E_ws(t) <= Emax_ws, E_ws(t) == E_ws(t-1)+dE(t)];
end
Walter Roberson
Walter Roberson le 16 Jan 2023
when t=1 then E_ws(t-1) is not a valid index

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by