0

Say I have a 256 by 256 matrix. I would like to replace any values that are 'greater' or 'equal' to 10 with 1 and make the rest 0 i.e. (values < 10).

For example,

2   3 6 15 24 32 1  7  39 10 ....

1   5 7 11 19 10 20 28 9 ........

10 24 6 29 10 25 32 10 ..........

.................................

.................................

and I want the output to be:

0 0 0 1 1 1 0 0 1 1 ............

0 0 0 1 1 1 1 1 0 ..............

1 1 0 1 1 1 1 1 ................

................................

................................

How can I do it?

HebeleHododo
  • 3,620
  • 1
  • 29
  • 38
Nadhris
  • 117
  • 2
  • 10

1 Answers1

3

Example:

a = [3  2  6  6 ; 
     7  5  3  7 ; 
     7 10  8  9 ; 
     2  4  3 10];

b = ( a > 5 )
b = 
     0     0     1     1
     1     0     0     1
     1     1     1     1
     0     0     0     1
Amro
  • 123,847
  • 25
  • 243
  • 454
  • 1
    you will not get this result since there are no number greater than 10 in a. Also you don't need parenthesis. – yuk Jul 26 '10 at 13:07
  • Ha, I didn't know you can put semicolons after each row in a, but it works. – yuk Jul 26 '10 at 13:08
  • @yuk: It looks like Amro meant to type `b = ( a > 5 )`, but he put `10` instead. – gnovice Jul 26 '10 at 13:51
  • yes of course, my bad.. also I like to put parentheses in such assignments as it makes the code more readable (to me at least) – Amro Jul 26 '10 at 18:32