Borrar filtros
Borrar filtros

for loop. finding the right index

1 visualización (últimos 30 días)
Ireedui Ganzorig
Ireedui Ganzorig el 18 de Mzo. de 2020
Comentada: Ireedui Ganzorig el 18 de Mzo. de 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', ])

Respuesta aceptada

David Goodmanson
David Goodmanson el 18 de Mzo. de 2020
Editada: David Goodmanson el 18 de Mzo. de 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 comentario
Ireedui Ganzorig
Ireedui Ganzorig el 18 de Mzo. de 2020
Thank you very much. You explained it very well. I got it. Thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by