for loop. finding the right index

1 Ansicht (letzte 30 Tage)
Ireedui Ganzorig
Ireedui Ganzorig am 18 Mär. 2020
Kommentiert: Ireedui Ganzorig am 18 Mär. 2020
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', ])

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 18 Mär. 2020
Bearbeitet: David Goodmanson am 18 Mär. 2020
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 Kommentar
Ireedui Ganzorig
Ireedui Ganzorig am 18 Mär. 2020
Thank you very much. You explained it very well. I got it. Thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by