Restricting a vector size

조회 수: 2 (최근 30일)
AB
AB 2017년 8월 30일
답변: Steven Lord 2017년 8월 30일
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

채택된 답변

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

추가 답변 (1개)

Steven Lord
Steven Lord 2017년 8월 30일
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.]

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by