Effacer les filtres
Effacer les filtres

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?

33 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

David Fletcher
David Fletcher le 29 Mar 2018
C=min(a,b)
D=minC==a

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by