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

5 vues (au cours des 30 derniers jours)
Islam
Islam le 27 Fév 2014
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..

Réponse acceptée

Friedrich
Friedrich le 27 Fév 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

Plus de réponses (1)

Jos (10584)
Jos (10584) le 27 Fév 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 "

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by