Restricting a vector size

4 visualizaciones (últimos 30 días)
AB
AB el 30 de Ag. de 2017
Respondida: Steven Lord el 30 de Ag. de 2017
Hi! I have a vector. I want to select values above a certain value and below a certain value eg: a=[1 2 3 4 5 6 7 8 9 10] I want to select all values between 2 and 6. How can I do that?
Thanks

Respuesta aceptada

Star Strider
Star Strider el 30 de Ag. de 2017
Try this:
a = [1 2 3 4 5 6 7 8 9 10];
Out = a(a >= 2 & a <= 6);

Más respuestas (1)

Steven Lord
Steven Lord el 30 de Ag. de 2017
Use logical indexing as described in the documentation, this post from Steve's blog or this post from Loren's blog. You want elements that satisfy the logical condition (greater than or equal to 2) and (less than or equal to 6) [I'm assuming "between" is inclusive in your question.]

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by