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

5 Ansichten (letzte 30 Tage)
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..

Akzeptierte Antwort

Friedrich
Friedrich am 27 Feb. 2014
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

Weitere Antworten (1)

Jos (10584)
Jos (10584) am 27 Feb. 2014
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 "

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by