Grouping consectuve datapoints from a table into an array
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Youssif Youssif
el 3 de Nov. de 2022
Respondida: Lei Hou
el 18 de Nov. de 2022
Hello,
I have atatched a picture of my 54x2 table. I was looking for help with my variable InstantPowerX. Basically, I would like a code that would organize consective numbers into an array called pulses. (For example, the first three point 20327,20328,20329 are consectuive, and they will be called pulse 1, 22516,22517,22518 are the next consectuive dataset and they will be stored in array called pulse 2 and so on) There should be a total of 18 pulses *18x3=54 since all data is 3 seconds in length before jumping to the next three seconds).
0 comentarios
Respuesta aceptada
Lei Hou
el 18 de Nov. de 2022
Hi Youssif,
Try the following code to see whether it works for you. The main idea is to use diff to find the group edge, and then use groupsummary to group row using the group edge information.
>> t = table([20327;20328;20329;22516;22517;22518;22519;25832;25833;28979],(1:10)','VariableNames',["InstantPowerX" "InstantPowerY"])
t =
10×2 table
InstantPowerX InstantPowerY
_____________ _____________
20327 1
20328 2
20329 3
22516 4
22517 5
22518 6
22519 7
25832 8
25833 9
28979 10
>> groupEdgeRowInex = [true; (diff(t.InstantPowerX) ~= 1)];
>> tOut = groupsummary(t,'InstantPowerX',[t.InstantPowerX(groupEdgeRowInex);t.InstantPowerX(end)],@(x){x})
tOut =
4×3 table
disc_InstantPowerX GroupCount fun1_InstantPowerY
__________________ __________ __________________
[20327, 22516) 3 {3×1 double}
[22516, 25832) 4 {4×1 double}
[25832, 28979) 2 {2×1 double}
[28979, 28979] 1 {[ 10]}
0 comentarios
Más respuestas (1)
David Hill
el 3 de Nov. de 2022
Best to keep all the data together. Just reshape the array and index into it.
pulse=reshape(yourTable.InstantPowerX,3,[])';%pulse1 would equal pulse(1,:), pulse2 would equal pulse(2,:)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!