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 Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by