Generating a new matrix

조회 수: 2 (최근 30일)
Offroad Jeep
Offroad Jeep 2016년 9월 16일
편집: Andrei Bobrov 2016년 9월 16일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2016년 9월 16일
편집: Andrei Bobrov 2016년 9월 16일
A = rand(4) >= .5;
Alpha = ~A * pi;

추가 답변 (1개)

KSSV
KSSV 2016년 9월 16일
편집: KSSV 2016년 9월 16일
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 ;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by