If statement with two possible outcomes

Hello,
Battprof=zeros(size(PVpower));
for i= 1:length(PVpower)
if PVpower(i)> 0
if PVpower(i)>0.5
Battprof(i)=0.5;
else
Battprof(i)=PVpower(i);
end
end
end
%SOC
SoCi=0;
SoC=zeros(size(Battprof));
for j=1:length(Battprof)
if j==1
SoC(j)=Battprof(j)+SoCi;
else
SoC(j)=Battprof(j-1)+SoC(j-1);
if SoC(j)>=5
SoC(j)=0;
end
end
end
In this code at the index j I would like to do two this if the value of SoC(j)>=5 I would like the value at that index to be zero and I would like the value of battprof(j) to be equal to -5.
for example:
If SoC(j)>=5 then SoC(j)=0 as well as Battprof(j)=-5
Could someone please help me with this
I would be really greatful

Respuestas (1)

David Hill
David Hill el 26 de Jul. de 2022
if SoC(j)>=5
SoC(j)=0;
Battprof(j)=-5;
end

2 comentarios

Ritika
Ritika el 27 de Jul. de 2022
Hi David!
Thank you for the answer. I dont want Battprof to be in the loop since it would change the values after. I would just like to replace the values at index j with -5 without effecting the values that follow
Thank you in advance
idx=[];
for j=1:length(Battprof)
if j==1
SoC(j)=Battprof(j)+SoCi;
else
SoC(j)=Battprof(j-1)+SoC(j-1);
if SoC(j)>=5
SoC(j)=0;
idx=[idx,j];
end
end
end
Battprof(idx)=-5;

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2022a

Preguntada:

el 26 de Jul. de 2022

Comentada:

el 27 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by