How to take from array elements that must fulfil a specific condition?

I have an array A and I need to create a new one with every previous number from A if the next number is less than certain known value M.
I'm just starting with Matlab and don't have any idea how to filter my array A this way.
Thank you in advance for your help.

Réponses (1)

Let's create a 1x10 array of values comprised between 0 and 1.
A = rand(1,10);
Let's assume you want to filter off all the values of A which are less than 0.5. You can do it like this:
A1 = A(A>=0.5);
I ran it on my pc, getting the following example result:
A = [0.0154 0.0430 0.1690 0.6491 0.7317 0.6477 0.4509 0.5470 0.2963 0.7447]
A1 = [0.6491 0.7317 0.6477 0.5470 0.7447]

Catégories

En savoir plus sur Entering Commands 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!

Translated by