calculate the maximum of every 24 data in matrices
2 次查看(过去 30 天)
显示 更早的评论
I have a series of data in .mat format, where each row determines a sensor and the columns are the data it collects every hour. The problem is that they are data that are taken every hour and I need the maximum of each day, that is, the maximum of each 24 values. taking into account that we have data from several years
0 个评论
采纳的回答
Star Strider
2023-3-20
If the times are in (or can be converted to) datetime arrays, one option would be to transpose the matrix so that the sensors are the columns (variables) and the times are the rows. Then use table2timetable and then retime. This is relatively straightforward to do, and has relevant examples in the retime documentation.
If those conditions apply and if you want specific help with it, upload/attach your data using the paperclip icon so we can work with it.
5 个评论
Star Strider
2023-3-21
I am not certain whiat data set you want to work with, so I duplicated this for each set —
LD1 = load(websave('date%201*552262','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1331305/date%201*552262.mat'));
data1 = LD1.sshobscorr
LD2 = load(websave('date','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1331300/date.mat'))
data2 = LD2.sshobscorrCopy
format shortG
NrNaN1 = nnz(isnan(data1))
data1 = data1(~isnan(data1))
numDays1 = numel(data1)/24
numDays1 = fix(numDays1)
data1 = data1(1:fix(numDays1)*24)
Tdata1 = reshape(data1,[],24).'
NrDays1 = size(Tdata1,2)
% calculate min and max for each day
dailyMin1 = min(Tdata1)
dailyMax1 = max(Tdata1)
NrNaN2 = nnz(isnan(data2))
data2 = data2(~isnan(data2))
numDays2 = numel(data2)/24
numDays2 = fix(numDays2)
data2 = data2(1:fix(numDays2)*24)
Tdata2 = reshape(data2,[],24).'
NrDays2 = size(Tdata2,2)
% calculate min and max for each day
dailyMin2 = min(Tdata2)
dailyMax2 = max(Tdata2)
There are no associated datetime values, so my idea will of course not work. Using reshape is the only option, however with all the NaN values, I am not certain if the usable data actually correspond to specific days or simply to sets of 24 values each. (I deleteed all the NaN values from each data set, because otherwise only the NaN values would be visible here. The non-NaN data would be in columns far off to the right.)
.
更多回答(1 个)
CAM
2023-3-20
Have you considered reshaping the 2D matrix into a 3D matrix -- (number of sensors) x 24 x days? Then you could use max for each row (sensor) within each day (3rd dim).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!