필터 지우기
필터 지우기

Extract Values from Matrix row

조회 수: 5 (최근 30일)
Denis Muhra
Denis Muhra 2021년 4월 12일
댓글: Adam Danz 2021년 4월 12일
Hi
I have a Dataset padded with -500 so the row length of the matrix stays the same. Now I want to extract an array from a row containing only the values that aren't -500.
e.g
A = [2,1,2,3,4,-500,-500,-500 ; 2,3,4,5,-500,-500,-500,-500]
i've tried this but it gives me only the boolean answer
A1 = A(1,:) > -500 -> A1 = [1,1,1,1,1,0,0,0]
what i want would be A1 = [2,1,2,3,4]
Can anybody help me?
Thanks in Advance

채택된 답변

David Fletcher
David Fletcher 2021년 4월 12일
You can use the logical vector to index the main array i.e
A(A1)
  댓글 수: 1
Adam Danz
Adam Danz 2021년 4월 12일
Better yet, combine them into 1 line,
A1 = A(1,A(1,:)~=-500)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by