0

I would like to select some numbers in a MATLAB matrix which have values greater than 4 and set them equal to zero.

For example:

A=[5 6 1 3 4 9 2 8 3];

Now, replace all values greater than 4 with zeros and store as a new matrix A1:

A1=[0 0 1 3 4 0 2 0 3]; 

1 Answer 1

6

You might want to try something like this:

A(A>4)=0

Here it is:

>> A=[5 6 1 3 4 9 2 8 3]

A =

     5     6     1     3     4     9     2     8     3

>> A(A>4)=0

A =

     0     0     1     3     4     0     2     0     3
2
  • yes, thanks a lot :), but I want to have it in a new matrix name such as A1=001340203
    – YSF
    Commented May 7, 2013 at 21:10
  • 3
    @YSF A1 = A; A1(A1 > 4) = 0;
    – Praetorian
    Commented May 7, 2013 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.