How to compare variable with a vector?

to_be_compared_with=[4160 13300 16800 30700 41000 63700 6050]; value=13311; %I want to find a value from vector close to 13311(Ans: 13300)

답변 (1개)

Stephen23
Stephen23 2018년 3월 9일
편집: Stephen23 2018년 3월 9일

0 개 추천

>> vec =[4160,13300,16800,30700,41000,63700,6050];
>> val = 13311;
>> [~,idx] = min(abs(vec-val));
>> vec(idx)
ans = 13300

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

태그

질문:

2018년 3월 9일

편집:

2018년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by