フィルターのクリア

Find a value which is on the same index as mulitple different values in a matrix

2 ビュー (過去 30 日間)
Oliver Hjertstedt Otterström
Oliver Hjertstedt Otterström 2021 年 4 月 27 日
回答済み: Himanshu 2024 年 2 月 23 日
I have a 3608x5 matrix which is year-month-date-time-energy at respective columns, where there are multiple datapoints every day. I have extracted the maximal values for one day manually placing the limits but want to extract the time of these values without getting a value from another day.
In this example I'm trying to get the timestamps in 8th of august but it doesn't work.
matrix=[year,month,date,time,energy]
max_day= [max energy consumption during a day]
for i=1:1:size(max_day)
time(i)=matrix(find(matrix(:,5)==max_day(i) & matrix(:,2)==8),4)
end

回答 (1 件)

Himanshu
Himanshu 2024 年 2 月 23 日
To my understanding you are trying to extract the value of time column for a particular day (8th august), corresponding to the maximum value of the ‘energy’ column on that day.
In the code shared by you, the issue lies in how you're filtering the data based on the date.
for i=1:1:size(max_day)
time(i)=matrix(find(matrix(:,5)==max_day(i) & matrix(:,2)==8),4)
end
  • matrix(:,5)==max_day(i) is comparing the energy values in your matrix with the maximal energy consumption for each day (max_day). This part of the condition is correct.
  • matrix(:,2)==8 is intended to filter the data for the 8th month (August). However, it doesn't consider the specific date. It checks if the month column in your matrix is equal to 8, but it doesn't ensure that the date corresponds to the 8th of August.
To filter the data for the 8th of August, you need to check both the month and date columns. In your original code, you only checked the month column matrix(:,2)==8, which is why it didn't correctly filter the data for the 8th of August.
Add a condition to check for the date in your code to achieve the desired result.
Hope this helps!

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by