replace zeros according to distribution of integers in each column
Ältere Kommentare anzeigen
if I have some matrix x of randomly distributed values (value 0 to n = 5 or 10 in this case)
x = [binornd( 5, 0.05, 10000, 1 ), binornd( 10, 0.1, 10000, 1 )];
I want to create a second matrix where any zeros in x are replaced at random by a value from 1 to n according to the distribution when zero is excluded in that particular column. I want to do this by random sampling from the values in each column excluding zero.
Any ideas how to do this quickly (in reality the matrices are considerably bigger than this example...)
Akzeptierte Antwort
Weitere Antworten (1)
Andriy Kavetsky
am 22 Okt. 2016
0 Stimmen
You can try this n=10; or n=5; and x(x==0)=randi(n)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!