matlab code to find the next highest integer

조회 수: 4 (최근 30일)
pavan sunder
pavan sunder 2016년 12월 5일
댓글: Walter Roberson 2018년 12월 13일
suppose i have a array a=[1 2 3 4 8 10 24] i have a random value for ex r=6;
i have to find the next highest integer to 6 in the given array i.e the output should be 8.
kindly help me with a matlab code

답변 (2개)

KSSV
KSSV 2016년 12월 5일
a=[1 2 3 4 8 10 24] ;
b = a(a>6) ;
iwant = b(1)

Jan
Jan 2016년 12월 5일
a = [1 2 3 4 8 10 24];
r = 6;
b = a(find(a > 6, 1));
  댓글 수: 2
shariq khan
shariq khan 2018년 12월 13일
This is more precise
Walter Roberson
Walter Roberson 2018년 12월 13일
slightly yes as it will not error if there were no matches .

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by