Select all eelements equal to a number

조회 수: 2 (최근 30일)
Daniel Boateng
Daniel Boateng 2019년 5월 14일
댓글: Daniel Boateng 2019년 5월 14일
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.

채택된 답변

Adam
Adam 2019년 5월 14일
b = x( 1:find( x == 4, 1, 'last' );

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by