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?

60 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

David Fletcher
David Fletcher el 29 de Mzo. de 2018
C=min(a,b)
D=minC==a

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by