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
David Hill 2022년 7월 26일

0 개 추천

if SoC(j)>=5
SoC(j)=0;
Battprof(j)=-5;
end

댓글 수: 2

Ritika
Ritika 2022년 7월 27일
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;

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 7월 26일

댓글:

2022년 7월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by