views:

48

answers:

1

Hi all,

I am really new with matlab and would like some helps with matlab.. Here is the problem:

Say if i have a 256 by 256 matrix. I would like to replace any values that are 'greater' or 'equal' to 10 with 'one' and name the rest as 'zero' i.e. (values <10).. How can I do it??

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 it to look like the bottom,

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 ...............

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

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

Thank you so much in advance with all your time... :)

+3  A: 

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
@Amro, you will not get this result since there are no number greater than 10 in a. Also you don't need parenthesis.
yuk
Ha, I didn't know you can put semicolons after each row in a, but it works.
yuk
@yuk: It looks like Amro meant to type `b = ( a > 5 )`, but he put `10` instead.
gnovice
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