Tags: 6and, elements, lt0, matlab, matrix, programming, suppose, values

Replace matrix elements

On Programmer » Matlab

419 words with 1 Comments; publish: Mon, 19 May 2008 00:13:00 GMT; (200109.38, « »)

Hi all,

I need your help. Suppose we have the matrix,

A = [0.3 0.2 0.8

0.9 0.5 0.3

0.2 0.0 0.6]

and we need to replace all the values <=0.5 by 0, and

those >.5 by its sqrt. In order to get,

B = [0 0 0.8944

0.9487 0 0

0 0 0.7746]

All your help are welcome.

Aris

All Comments

Leave a comment...

  • 1 Comments
    • Hi,

      try this :

      (A>.5).*sqrt(A)

      %or

      sqrt(A.*(A>.5))

      Jrme

      #1; Mon, 19 May 2008 00:14:00 GMT