how to build a new matrix with reference to the index of another matrix ?
4 次查看(过去 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..
0 个评论
采纳的回答
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
0 个评论
更多回答(1 个)
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 "
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!