필터 지우기
필터 지우기

I can I do logical indexing on a column

조회 수: 1 (최근 30일)
Engdaw Chane
Engdaw Chane 2018년 7월 20일
댓글: Engdaw Chane 2018년 7월 20일
Hello everyone,
I have a column which is 840 in length. It contains value s from -12 to 12. I need only values < -8 and >8. I need to keep the length 840. I tried the following. but it says " 0x1 empty double column vector".
v = zeros (size (data)); % Pre-allocate!
v=data(data <-8 & data>8)
thank you for helping.
Chane

채택된 답변

Birdman
Birdman 2018년 7월 20일
편집: Birdman 2018년 7월 20일
Is it possible for a value to be smaller than -8 and greater than 8 at the same time? Check your logical operator. You need OR operator instead of AND.
v=data(data <-8 | data>8)
You can not keep the length same. If you want that, fill the other values with a specific value, like zero.
  댓글 수: 5
Guillaume
Guillaume 2018년 7월 20일
편집: Guillaume 2018년 7월 20일
Well, if you want to replace values less than absolute 8 by 0, then:
v(abs(v) < 8) = 0;
You may want <= instead of <
Engdaw Chane
Engdaw Chane 2018년 7월 20일
Birdman and Guillaume, Thank you!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by