calculate the maximum of every 24 data in matrices

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Star Strider
Star Strider el 20 de Mzo. de 2023
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 comentarios
Victoria Pilar Quesada García
Victoria Pilar Quesada García el 21 de Mzo. de 2023
I think I've got a way but it can only be applied to one row.Is there a way to use it for more than one row at the same time? or another way I have to do it?
load("date 1*552262.mat")
data=sshobscorr
%total number of days of data
numDays = length(data)/24;
% temperature data so i have a column for each day, with a row for each hour in the day
Tdata = reshape(data,24,numDays)
% calculate min and max for each day
dailyMin = min(Tdata);
dailyMax = max(Tdata);
Star Strider
Star Strider el 21 de Mzo. de 2023
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
data1 = 1×552264
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
LD2 = load(websave('date','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1331300/date.mat'))
LD2 = struct with fields:
sshobscorrCopy: [485×999 double]
data2 = LD2.sshobscorrCopy
data2 = 485×999
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
format shortG
NrNaN1 = nnz(isnan(data1))
NrNaN1 =
435232
data1 = data1(~isnan(data1))
data1 = 1×117032
0.1358 0.18396 0.12512 0.041191 0.044977 -0.011474 -0.035863 -0.07526 -0.10174 -0.14825 -0.19642 -0.22789 -0.25987 -0.27876 -0.24913 -0.26042 -0.21822 -0.19 -0.12006 -0.05785 -0.028557 0.042862 0.075869 0.092993 0.11776 0.11377 0.14235 0.15074 0.1391 0.15539
numDays1 = numel(data1)/24
numDays1 =
4876.3
numDays1 = fix(numDays1)
numDays1 =
4876
data1 = data1(1:fix(numDays1)*24)
data1 = 1×117024
0.1358 0.18396 0.12512 0.041191 0.044977 -0.011474 -0.035863 -0.07526 -0.10174 -0.14825 -0.19642 -0.22789 -0.25987 -0.27876 -0.24913 -0.26042 -0.21822 -0.19 -0.12006 -0.05785 -0.028557 0.042862 0.075869 0.092993 0.11776 0.11377 0.14235 0.15074 0.1391 0.15539
Tdata1 = reshape(data1,[],24).'
Tdata1 = 24×4876
0.1358 0.18396 0.12512 0.041191 0.044977 -0.011474 -0.035863 -0.07526 -0.10174 -0.14825 -0.19642 -0.22789 -0.25987 -0.27876 -0.24913 -0.26042 -0.21822 -0.19 -0.12006 -0.05785 -0.028557 0.042862 0.075869 0.092993 0.11776 0.11377 0.14235 0.15074 0.1391 0.15539 0.14452 0.13723 0.12455 0.10996 0.10092 0.079247 0.07611 0.087974 0.079477 0.068379 0.07165 0.074181 0.051074 0.042777 0.041157 0.038698 0.039821 0.028684 0.03321 0.046506 0.056262 0.06525 0.067504 0.084538 0.10842 0.12537 0.1243 0.137 0.14909 0.14529 0.10362 0.12894 0.15837 0.17844 0.17396 0.19869 0.20682 0.2057 0.19785 0.22796 0.2714 0.26557 0.25416 0.27252 0.2891 0.31791 0.36479 0.40764 0.45489 0.51208 0.54332 0.56781 0.58432 0.56405 0.55173 0.48655 0.44869 0.42835 0.37039 0.38935 -0.11646 -0.10988 -0.10829 -0.11861 -0.11942 -0.10706 -0.10936 -0.098284 -0.083261 -0.060146 -0.082538 -0.09234 -0.059585 -0.061251 -0.042755 -0.040799 -0.043754 -0.00236 -0.0087156 -0.015605 0.0066368 0.0046152 -0.012923 -0.0034358 0.025132 0.03125 0.023931 0.019935 0.023892 0.048275 -0.17868 -0.18342 -0.16958 -0.15358 -0.15685 -0.16677 -0.15562 -0.16205 -0.17291 -0.16663 -0.1906 -0.18738 -0.19348 -0.2006 -0.18739 -0.1938 -0.18145 -0.16909 -0.17255 -0.15634 -0.15946 -0.17631 -0.17987 -0.16758 -0.1776 -0.17209 -0.17048 -0.16351 -0.16263 -0.17524 -0.0093065 0.0057132 0.0098779 0.0044814 -0.014395 -0.01924 -0.0099304 0.012665 0.035563 0.041382 0.051966 0.06255 0.04795 0.034493 0.014188 0.011365 0.013614 0.0052942 0.011499 0.01362 0.021708 0.033427 0.037044 0.038607 0.04125 0.042373 0.028179 0.020786 0.013388 -0.0070962 -0.078911 -0.083773 -0.095854 -0.1102 -0.11643 -0.12814 -0.13237 -0.14513 -0.14621 -0.16094 -0.15157 -0.13185 -0.12836 -0.13093 -0.13938 -0.1333 -0.13858 -0.16805 -0.1567 -0.1496 -0.16208 -0.15261 -0.16681 -0.15205 -0.13031 -0.13669 -0.12592 -0.1381 -0.13605 -0.15087 0.039727 0.052571 0.046197 0.032427 0.03061 0.011015 0.019031 0.01705 -0.00062475 -0.0035273 -0.023838 -0.018832 -0.014416 -0.019046 -0.021594 -0.0065405 0.0058677 0.0017217 -0.0019562 0.0048748 -0.0066606 -0.034108 0.013164 0.037463 0.032775 0.044383 0.033484 0.056718 0.067816 0.046404 -0.14158 -0.1492 -0.1744 -0.16202 -0.15577 -0.1542 -0.14889 -0.14488 -0.14329 -0.15838 -0.15251 -0.16155 -0.18317 -0.16549 -0.17934 -0.181 -0.16091 -0.15276 -0.13753 -0.15693 -0.16771 -0.15249 -0.14442 -0.12789 -0.13841 -0.13602 -0.10903 -0.11605 -0.10774 -0.11599 0.10348 0.10462 0.12052 0.13643 0.1379 0.15332 0.10739 0.095572 0.081549 0.06506 0.062693 0.058498 0.077473 0.079918 0.056529 0.059922 0.090013 0.13258 0.14799 0.16328 0.20035 0.21319 0.20046 0.19127 0.20181 0.17847 0.16137 0.17729 0.15474 0.14306
NrDays1 = size(Tdata1,2)
NrDays1 =
4876
% calculate min and max for each day
dailyMin1 = min(Tdata1)
dailyMin1 = 1×4876
-0.2465 -0.277 -0.26209 -0.27948 -0.27054 -0.288 -0.2515 -0.25291 -0.26441 -0.26114 -0.27178 -0.28542 -0.2709 -0.28054 -0.27059 -0.26042 -0.27066 -0.23581 -0.22626 -0.23399 -0.22192 -0.2102 -0.18272 -0.22591 -0.2177 -0.18819 -0.19151 -0.17306 -0.18834 -0.17524
dailyMax1 = max(Tdata1)
dailyMax1 = 1×4876
0.14452 0.18396 0.15837 0.17844 0.17396 0.19869 0.20682 0.2057 0.20472 0.22796 0.2714 0.33797 0.38559 0.45053 0.461 0.40301 0.42617 0.40764 0.45489 0.51208 0.54332 0.56781 0.58432 0.56405 0.55173 0.48655 0.44869 0.42835 0.37039 0.38935
NrNaN2 = nnz(isnan(data2))
NrNaN2 =
448906
data2 = data2(~isnan(data2))
data2 = 35609×1
0.042969 0.0080714 0.0076017 -0.17217 0.2407 0.22599 0.24472 0.18292 0.14108 0.43792
numDays2 = numel(data2)/24
numDays2 =
1483.7
numDays2 = fix(numDays2)
numDays2 =
1483
data2 = data2(1:fix(numDays2)*24)
data2 = 35592×1
0.042969 0.0080714 0.0076017 -0.17217 0.2407 0.22599 0.24472 0.18292 0.14108 0.43792
Tdata2 = reshape(data2,[],24).'
Tdata2 = 24×1483
0.042969 0.0080714 0.0076017 -0.17217 0.2407 0.22599 0.24472 0.18292 0.14108 0.43792 0.16903 -0.096736 0.24944 0.026714 0.29188 0.34562 0.046633 -0.029092 -0.014236 -0.012677 0.0051745 0.29123 0.25167 0.070853 0.29805 0.14225 0.14928 0.14814 -0.056768 0.4183 0.40759 0.16766 0.87529 0.87734 0.38444 0.19761 0.036653 0.02588 0.095001 0.094382 -0.34344 -0.18514 -0.15477 1.3688 0.40444 -0.048043 -0.051517 -0.044927 0.28443 0.22334 -0.033382 0.23675 0.21123 0.22949 -0.090283 -0.068657 1.1169 -0.02506 0.1552 -0.12068 -0.12797 -0.096339 0.032571 0.0079394 -0.018924 -0.056825 0.41201 -0.087299 -0.022903 -0.06116 -0.063732 -0.10597 -0.10325 0.14256 0.15433 0.36148 -0.091025 -0.057225 0.01907 0.097346 0.09677 0.052912 0.2459 0.027406 -0.0041486 -0.097538 -0.094861 -0.21416 -0.090903 -0.064856 0.32447 0.20142 0.28844 0.1113 0.042889 0.048707 -0.01153 0.14548 0.16812 0.2937 0.091153 0.29312 -0.036761 -0.0086433 0.26756 0.064993 -0.042574 0.19723 0.17687 0.26203 0.035154 0.053754 0.22424 -0.047574 0.13037 0.12771 -0.10648 -0.0072317 -0.0057692 -0.11864 0.016319 -0.026082 -0.015622 0.1286 -0.061284 -0.021463 -0.15624 -0.067284 -0.055541 -0.053029 -0.2316 -0.24488 0.27277 0.045762 0.090873 0.10787 0.33128 0.334 0.040706 0.0807 0.016541 -0.032657 -0.050981 -0.049387 -0.2882 -0.14799 -0.12434 0.23611 0.092414 -0.14284 -0.12738 0.38328 -0.06186 -0.14896 -0.26218 -0.26311 -0.16655 -0.01835 0.0016429 0.03829 -0.078869 -0.069505 -0.1098 -0.1615 -0.17123 -0.16298 -0.015523 -0.092838 -0.11367 -0.14074 0.10033 0.1184 0.018203 -0.074161 -0.17304 0.00030183 -0.1192 -0.014064 -0.014385 -0.41714 0.13508 0.14591 0.50803 0.059652 0.072045 -0.011699 0.04807 0.11747 0.11963 0.31272 0.31998 0.55422 0.34655 0.38402 0.34963 0.35385 0.35366 0.27473 0.20782 0.097461 -0.08328 0.090962 0.097096 -0.14116 -0.022805 0.0038252 0.38136 -0.20596 0.032469 -0.05595 -0.043174 0.087832 0.052321 -0.0069475 0.03827 -0.01425 0.078169 0.10457 0.086145 0.099214 0.037712 0.053729 0.14658 0.071793 -0.060834 0.14612 -0.049222 0.10412 0.10267 -0.23512 -0.23825 0.055851 0.25873 0.29035 0.023673 0.063937 0.065537 0.12775 0.010922 0.10167 0.062069 -0.013435 -0.017149 0.1767 0.10487 0.27022 0.034147 0.034968 0.037019 0.2385 0.25673 0.13493 0.026021 0.31059 0.080356 0.13572 0.13397 0.25689 0.012042 0.24341 0.2245 0.21883 0.13161 0.14884 0.099209 -0.012098 0.11441 0.31337 0.00032963 0.024622 -0.053575 -0.1314 -0.14669 0.059919 0.065851 0.089178 0.21813 0.21688 0.21868 -0.045401 0.18086 0.047557 -0.0066763 -0.048877 -0.04565 -0.19126 -0.085339 -0.061679 0.043619 -0.026537 -0.1292 -0.023858 -0.11686 -0.0729 0.075209 -0.073848 0.012615 -0.0079333 0.0080566 -0.063208
NrDays2 = size(Tdata2,2)
NrDays2 =
1483
% calculate min and max for each day
dailyMin2 = min(Tdata2)
dailyMin2 = 1×1483
-0.32602 -0.32704 -0.53564 -0.21545 -0.26218 -0.44455 -0.26066 -0.2626 -0.39712 -0.3983 -0.57187 -0.39345 -0.38498 -0.24448 -0.35454 -0.3531 -0.28971 -0.3292 -0.38221 -0.37623 -0.34699 -0.25698 -0.18386 -0.29296 -0.58517 -0.34078 -0.2518 -0.21416 -0.4546 -0.44964
dailyMax2 = max(Tdata2)
dailyMax2 = 1×1483
0.49457 0.40117 0.87529 0.87734 0.38444 0.27022 0.41201 0.35795 0.74142 0.43792 0.31998 0.55422 0.41044 1.3688 0.40444 0.55152 0.55415 0.50979 0.46801 0.48776 0.55602 0.50783 0.50512 0.43114 0.41305 0.23216 1.1169 0.31337 0.20491 0.4183
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.)
.

Iniciar sesión para comentar.

Más respuestas (1)

CAM
CAM el 20 de Mzo. de 2023
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).
  1 comentario
Victoria Pilar Quesada García
Victoria Pilar Quesada García el 20 de Mzo. de 2023
I wouldn't really know how to do it, for now I only have a 485*552262 matrix with NaN and numbers. If, in the way you say, I would divide those 552262 into groups of 24 values ​​and then calculate the max, it would be perfect.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by