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)

Respuestas (1)

Stephen23
Stephen23 el 9 de Mzo. de 2018
Editada: Stephen23 el 9 de Mzo. de 2018
>> vec =[4160,13300,16800,30700,41000,63700,6050];
>> val = 13311;
>> [~,idx] = min(abs(vec-val));
>> vec(idx)
ans = 13300

Categorías

Más información sobre Aerospace Blockset en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Mzo. de 2018

Editada:

el 9 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by