how to build a new matrix with reference to the index of another matrix ?

조회 수: 5 (최근 30일)
I have a matrix cost(i,j)= cost(3,5)=
[ 0 0 -1.5572 0.2352 0
0 -3.2616 0 0 5.1371
-2.8496 0 0 0 0 ]
and I want to have MM(i,j) that the same of the above, but for each non-negative value will have zero . Thus, MM should be
[ 0 0 -1.5572 0 0
0 -3.2616 0 0 0
-2.8496 0 0 0 0 ]
Also, I want to have a RR(i,j) matrix that has one for each negative value. Thus, RR will be
[ 0 0 1 0 0
0 1 0 0 0
1 0 0 0 0 ]
Thanks a lot, extreme thanks..

채택된 답변

Friedrich
Friedrich 2014년 2월 27일
Hi,
try this
A = [ 0 0 -1.5572 0.2352 0
0 -3.2616 0 0 5.1371
-2.8496 0 0 0 0 ]
MM = A;
MM(A>0) = 0
RR = MM;
RR(MM<0) = 1

추가 답변 (1개)

Jos (10584)
Jos (10584) 2014년 2월 27일
MM = min(cost,0)
RR = cost<0
btw, the notation cost(i,j) means the element in the i-th row and j-th column of the array cost. I think you intend to say that cost has i rows and j columns. In that case, the following is more clear: " I have an i-by-j array cost "

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by