If statement with two possible outcomes
Show older comments
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
Answers (1)
David Hill
on 26 Jul 2022
if SoC(j)>=5
SoC(j)=0;
Battprof(j)=-5;
end
2 Comments
Ritika
on 27 Jul 2022
David Hill
on 27 Jul 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;
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!