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
답변 (1개)
David Hill
2022년 7월 26일
if SoC(j)>=5
SoC(j)=0;
Battprof(j)=-5;
end
댓글 수: 2
Ritika
2022년 7월 27일
David Hill
2022년 7월 27일
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;
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!