How to find longest lasting event
Mostrar comentarios más antiguos
How to find longest lasting event?
means i wanna Calculate the duration of each event as the difference between 2 function..
1 comentario
dpb
el 24 de Mayo de 2020
If use the duration class variable, then it's a simple as subtraction...
Respuestas (2)
Image Analyst
el 24 de Mayo de 2020
What form is your event data in? Is it like a binary vector [0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0]?
% 1's are in the event and 0's are where the event is not happening.
inEvent = logical([0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0])
% Extract the longest one and sum up the number of indexes of it.
longestDuration = sum(bwareafilt(inEvent, 1))
inEvent =
1×16 logical array
0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 0
longestDuration =
6
7 comentarios
Attaullah Shafiq
el 24 de Mayo de 2020
dpb
el 24 de Mayo de 2020
Well, that's nice....but how are we to know when you keep what it actually is a deep, dark secret?
Without showing us what you have, all we can do is guess.
As noted above, if you'll turn the function outputs into either a real time or duration containing a starting time, then you can simply subtract the results.
If the functions themselves can't be modified, then cast the result of the function first.
Attaullah Shafiq
el 24 de Mayo de 2020
Image Analyst
el 24 de Mayo de 2020
So, it looks like homework. I never heard of the groupsummary function, but there is a grpstats() function in the Statistics and Machine Learning Toolbox.
Anyway, with 2 they basically showed you how to do it. Just take everything in bold and string them together. It's trivial. Really basic MATLAB indexing stuff. If you still don't know how, then you can save a lot of time in the future if you just invest 2 hours now by watching this : MATLAB Academy - free 2 hour training
Attaullah Shafiq
el 24 de Mayo de 2020
dpb
el 24 de Mayo de 2020
@IA, groupsummary is relatively recent addition to the splitapply workflow toolkit -- R2018x? I think or thereabouts.
It's another case of essentially the same functionality as a Toolbox function being migrated to base product excepting w/ a different name and slightly different syntax.
Image Analyst
el 24 de Mayo de 2020
Right you are. Cool, thanks. 👍
ahmed ibrahim
el 11 de En. de 2021
0 votos
What row in the data set does this correspond to (remember that min and max have a 2nd output that gives the row)?
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
