for loop. finding the right index
1 次查看(过去 30 天)
显示 更早的评论
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', ])
0 个评论
采纳的回答
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).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!