How to extract values from an array?
Afficher commentaires plus anciens
Hello all,
I have an array with values that repeat , is it possible to determine the start and end points of a particular value in the array. For example
array = [10 10 10 30 30 30 30 30 4 4 4 4 4 30 30 30 30 30 30 2 2 2 2 2 30 30 30 30];
the goal is to extract those values in between the 30s.
How can i go about this? Thanks
4 commentaires
Rik
le 9 Mar 2022
What would be the intended output? Perhaps this?
new_array=[4 2];
You can probably use most of the RunLength function Jan published on the file exchange.
Daniel Adeniyi
le 9 Mar 2022
Rik
le 9 Mar 2022
If you want to extract the numbers, do you mean you want [4 2], or [4 4 4 4 4 2 2 2 2 2];? (or something else)
That is also probably important information if David's answer doesn't work for you.
Daniel Adeniyi
le 9 Mar 2022
Réponse acceptée
Plus de réponses (1)
David Hill
le 9 Mar 2022
a=num2str(yourArray==30);
a=a(a~=' ');
[s,f]=regexp(a,'[1]*');
new_array=[s,f];
1 commentaire
Daniel Adeniyi
le 9 Mar 2022
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!