How to take from array elements that must fulfil a specific condition?
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Davide Masiello
on 4 Feb 2022
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]
0 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!