I have two matrices and I want to take the minimum of them and then set the value in the minimum matrix to 0 if it comes from matrix A and 1 if it comes from matrix B. How do I do this?

35 次查看(过去 30 天)
Hi all,
I have two matrices of random variable from specific distributions with specific parameters. Consider them matrix A and matrix B. I want to observe the minimum{A,B}. But I need to know from which matrix the minimum value came from and then, if it comes from matrix A, set it equal to 1 and if it comes from matrix B, set it equal to 0.
Essentially, I'm building a random vector of censored units. So I know that I want to find:
C = min(A,B) % which givens me a matrix that's the same size of A and B of the minimum value, element-wise between A and B.
But then, I need a way to code that if the element i in C comes from A, then for a new matrix of the same size, D, the ith element of D = 1. And if the ith element in C comes from B, then the ith element of D = 0.
Can anyone help me with this?
Thank you.

采纳的回答

David Fletcher
David Fletcher 2018-3-29
C=min(a,b)
D=minC==a

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by