Borrar filtros
Borrar filtros

How to create a weighted random number in matrix?

1 visualización (últimos 30 días)
Irina
Irina el 2 de Ag. de 2013
I want to assign weighted random values to a matrix. The two values I am assigning are 0 and 1. A point needs to have a 60% probability of being assigned 0 and 40% of being assigned 1. How do I code that?

Respuestas (1)

John Petersen
John Petersen el 2 de Ag. de 2013
a = rand(10); % 10x10 matrix
b = a>.6; % all elements of a > .6 are 1 all < .6 are 0
60% should be 1's, 40 % should be zeros You can test by sum(sum(b))/100
  2 comentarios
Irina
Irina el 2 de Ag. de 2013
I phrased the question incorrectly, I'm sorry. Point values are either 0 or 1. The value of point (x,y) is based on the value of point (x-1,y). If (x-1,y) is 1, then (x,y) has a 60% chance of being 1 and 40% chance of being 0. Do you know how to code for that?
John Petersen
John Petersen el 9 de Ag. de 2013
Editada: John Petersen el 9 de Ag. de 2013
I don't see how that makes the problem different.
a = rand(1)>.6;
This says that the value of 'a' will be either 0 or 1 and has a 60% chance of being a 1.

Iniciar sesión para comentar.

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