필터 지우기
필터 지우기

extracting a range of values from a vector

조회 수: 15 (최근 30일)
giuseppe insignito
giuseppe insignito 2020년 11월 18일
댓글: HabenG 2021년 12월 1일
I have an array indx = [ 1 7 4 8 11 6 3] and I need to extract from 1 (minimum) to 4 (maximum) of the actual value (Not the index!) of the elements of indx and put them into another array indx_w (wich results in this case = [1 3 4])
How to do it?
indx_w = ????
thanks!

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 18일
편집: Ameer Hamza 2020년 11월 18일
You can use logical indexing
indx = [ 1 7 4 8 11 6 3];
lb = 1;
ub = 4;
mask = (indx >= lb) & (indx <= ub);
indx_w = indx(mask)
If you also want the output to be sorted
indx_w = sort(indx_w)
  댓글 수: 2
giuseppe insignito
giuseppe insignito 2020년 11월 18일
I've found something even easier:
indx_w = indx(indx >= 1 & indx <= 4)
:)
HabenG
HabenG 2021년 12월 1일
Clutch!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by