필터 지우기
필터 지우기

non zero elements above 70 and below -70 zero

조회 수: 2 (최근 30일)
Jeroen
Jeroen 2012년 2월 17일
편집: Jan 2013년 10월 15일
hello people,
In a matrix I want that all non zero elements above 70 and below -70 is zero.
How do I do that ?
Thank you!

답변 (4개)

Honglei Chen
Honglei Chen 2012년 2월 17일
Use logical index
x(x>70 | x<-70)=0
  댓글 수: 2
Jeroen
Jeroen 2012년 2월 17일
and what if I want to replace only those elements in the first two rows?
Honglei Chen
Honglei Chen 2012년 2월 17일
See carmen's answer below

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


the cyclist
the cyclist 2012년 2월 17일
I am not 100% sure what you mean, but here is some code (with comments on my understanding) that you should be able to modify to do what you want
% Some test data:
A = 200*rand(100) - 100;
% Index to values you want to zero out
idx = (A>70) | (A<-70); % Index to values that are bigger than 70 or smaller than -70
% Zero those out
A(idx) = 0;
  댓글 수: 1
Jeroen
Jeroen 2012년 2월 17일
Thank you!
Well it is a matrix of ~40000 by 6. But what if I want to replace only those elements in the first two rows?

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


carmen
carmen 2012년 2월 17일
then you modify Honglei Chen 's approach according to your wish:
x(1:2,x(1:2,:)>70 | x(1:2,:)<-70)=0
that should be it.

Sean de Wolski
Sean de Wolski 2012년 2월 17일
A(abs(A)>70) = 0;

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by