# Generating a new matrix

1 view (last 30 days)
Offroad Jeep on 16 Sep 2016
Edited: Andrei Bobrov on 16 Sep 2016
Let A be a matrix A = rand(4) For all values of A >=0.5, A = 1 else A = 0
now I want to generate a new matrix Alpha..... for which all values of A which are 1 they should have value 0 in Alpha matrix and for all zero values of matrix A the Alpha should have value "pi"
Let A = [1,0;0,0] Alpha should be [0,pi;pi,pi]
Thanks for helpers....... hope i made you understand what i want.... Regards
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Andrei Bobrov on 16 Sep 2016
Edited: Andrei Bobrov on 16 Sep 2016
A = rand(4) >= .5;
Alpha = ~A * pi;
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

KSSV on 16 Sep 2016
Edited: KSSV on 16 Sep 2016
A = [1,0;0,0] ;
iwant = A ;
iwant(A==1) = 0 ;
iwant(A==0) = pi ;
A = rand(4) ;
iwant = A ;
iwant(A>=0.5) = 1 ;
iwant(A<0.5) = 0 ;
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Categories

Find more on Detection in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!