YSF
YSF

Reputation: 47

Choose specific values in matrix in MATLAB

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]; 

Upvotes: 0

Views: 269

Answers (1)

Oliver Amundsen
Oliver Amundsen

Reputation: 1511

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

Upvotes: 6

Related Questions