If statement with two possible outcomes
Mostrar comentarios más antiguos
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
el 26 de Jul. de 2022
if SoC(j)>=5
SoC(j)=0;
Battprof(j)=-5;
end
2 comentarios
Ritika
el 27 de Jul. de 2022
David Hill
el 27 de Jul. de 2022
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;
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!