How to find index in cell array to start cumsum
Ältere Kommentare anzeigen
Hello, I have a cell array 'ddvaluecell'.
I would like to find the index of values in these cells which are > 0.5.
Then starts a cumsum for the next 5 indices or stop early when it reaches 3.
How do I do this?
5 Kommentare
Walter Roberson
am 7 Mär. 2021
indices = cellfun(@(C) find(C>0.5), ddvaluecell, 'uniform', 0);
Jonathan Cheong
am 7 Mär. 2021
Walter Roberson
am 7 Mär. 2021
I would suggest that you write straight forward loops for this task. Get the code working first. Look for opportunities for optimization later once you have working code you can test against.
And remember that vectorizing is not always the best approach. If you are struggling to package the results and to figure out how to feed the data in and out of the vectorized forms then you are losing clarity and running the risk that the convoluted forms are slower than looping.
Walter Roberson
am 7 Mär. 2021
Also take the time to decide what you want to do if there are multiple nearby values that meet the test. Do you want to process separately for each possible starting point Do you want to bundle all of the values within a window of 5 together only making one start for the window? Even if the sum ends early? Do you want to bundle all consecutive >½ together but only take starting from the first of the group?
Jonathan Cheong
am 7 Mär. 2021
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!