Truncation of elements in MATLAB Array

Status
Not open for further replies.

pancho_hideboo

Advanced Member level 5
Joined
Oct 21, 2006
Messages
2,847
Helped
767
Reputation
1,536
Reaction score
733
Trophy points
1,393
Location
Real Homeless
Activity points
17,490
I would like to set zero for elements whose absolute is lesser than 10 in MATLAB Array.

Now I use following MATLAB code for this purpose.
However this is not cool.
Is there any cool method ?
Code:
>> A=[1000, 200, 3, 10]

A =

        1000         200           3          10

>> for(i=1:length(A))
if abs(A(i)) < 10, A(i)=0; end
end
>> A

A =

        1000         200           0          10

>>
 

Code:
octave> A=[1000, 200, 3, 10]
A =

   1000    200      3     10

octave> A=A.*(abs(A)>=10)
A =

   1000    200      0     10
 

Code:
>> A=[1000, 200, 3, 10]

A =

        1000         200           3          10

>> A( find(abs(A) < 10) ) = 0;
>> A

A =

        1000         200           0          10

>>
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…