MATLAB Answers

0

Select all eelements equal to a number

Asked by Daniel Boateng on 14 May 2019
Latest activity Commented on by Daniel Boateng on 14 May 2019
I have an array of elements x= [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 7 7 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7];
I want to write a script that starts checking the array from the last element and when this is equal to 4 , it breaks and returns the rest of the array say b= [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 7 7 4 4 4];
Please any help.
Thank you.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Adam
on 14 May 2019
 Accepted Answer

b = x( 1:find( x == 4, 1, 'last' );

  1 Comment

thank you very much

Sign in to comment.