필터 지우기
필터 지우기

for loop. finding the right index

조회 수: 1 (최근 30일)
Ireedui Ganzorig
Ireedui Ganzorig 2020년 3월 18일
댓글: Ireedui Ganzorig 2020년 3월 18일
Hello MATLAB community,
stateOfEnergy is a bunch of data in a column, and I found the largest increase and decrease of stateOfEnergy by utilizing the for loop and built-in <max> and <min>. But I am really struggling to find indices where the largest increase and decrease occured. Below is my code. Is therer any way you can find that specific indices?
stateOfEnergy = load('40815SOE.csv'); % in kiloWattHour
for i = 2 : length(stateOfEnergy)
changeInSOE(i-1) = stateOfEnergy(i) - stateOfEnergy(i-1);
end
largestIncrease = max(changeInSOE); % largest increase of change in SOE in invertal of a single minute. in kWh
disp(['The Largest Increase in SOE was ', num2str(largestIncrease), 'kWh was found between index', ])
largestDecrease = min(changeInSOE); % % largest decrease of change in SOE in invertal of a single minute. in kWh
disp(['The Largest Decrease in SOE was ', num2str(largestDecrease), 'kWh was found between index', ])

채택된 답변

David Goodmanson
David Goodmanson 2020년 3월 18일
편집: David Goodmanson 2020년 3월 18일
Hello Ireedui,
max and min find the indices as well as the values.
changeInSOE = diff(stateOfEnergy) % find all the differences
[valmax indmax] = max(changeInSOE)
[valmin indmin] = min(changeInSOE)
indmax = n says that the largest positive change of value = valmax occurred from stateOfEnergy(n) to stateOfEnergy(n+1).
indmin = m says that the largest negative change of value = valmin occurred from stateOfEnergy(m) to stateOfEnergy(m+1).
  댓글 수: 1
Ireedui Ganzorig
Ireedui Ganzorig 2020년 3월 18일
Thank you very much. You explained it very well. I got it. Thanks.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by