How can I merge successive row values (sum of the values) of the column Y according to a condition in column X?

1 vue (au cours des 30 derniers jours)
Dear,
Hope everyone is doing well!
My issue is: I have a two data columns (X and Y) and datime column (10 min interval). I want to merge the successive row values (sum) of column Y if the corresponding values of column X are 0. Otherwise, if one of the X row equals to 1, then no merge.
Knowing that X contains only 0 and 1 values.
Thank you for your collaboration.
  2 commentaires
Matt J
Matt J le 19 Avr 2022
Doesn't that mean that all the Y values in the data you've shown will be summed? There are no ones in the X column at all, so why have you designated only the specific rows circled in red?
Peter Perkins
Peter Perkins le 18 Mai 2022
Also you have not said what merging does to the timestamps.

Connectez-vous pour commenter.

Réponses (1)

Peter Perkins
Peter Perkins le 18 Mai 2022
You want to do grouped sums, where the groups are defined by consecutive zeros in X. Once you have the groups defined as a new variable in (what should be) a timetable, it's a simple matter of calling groupsummary. Usually defining groups like that involves tricks with cumsum and diff. But without a clear example of what you have and what you want, I won't hazard a guess.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by