How to compare a number with values of a vector?

1 回表示 (過去 30 日間)
Ahmad Hasnain
Ahmad Hasnain 2018 年 9 月 21 日
回答済み: Fangjun Jiang 2018 年 9 月 21 日
I have a vector. For example
A = [20 40 60 80 100 120]
I have a number as an input in a function
function imp(omega)
I need to compare the number omega with all the numbers of the vector. For example, the number is 30. I know 30 is in between 20 and 40. How do I find that by code?

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 9 月 21 日
A = [20 40 60 80 100 120];
x=30;
lowB=interp1(A,A,x,'previous')
HighB=interp1(A,A,x,'next')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by