for loop. finding the right index
1 回表示 (過去 30 日間)
古いコメントを表示
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', ])
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 で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!