필터 지우기
필터 지우기

Random Binary Matrix with certain weight

조회 수: 3 (최근 30일)
Moe Joe
Moe Joe 2016년 11월 25일
댓글: John BG 2016년 12월 1일
In leaner codes (n,k), I want to generate a random binary matrix of size (1, n) with weight (t)
I can use A = randi ([0 1], 1, n); OR A=fix(2*rand(1,n));
But this will generate a matrix A of different weights. To get a vector of weight (t), will need exhaustive search which is time-consuming.
I need a command that can generate this matrix or vector of weight (t) distributed randomly in A=(1,n).
Can you help pls?

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 25일
v = [ones(1,t), zeros(1,n-t)];
A = v( randperm(n) );

추가 답변 (1개)

John BG
John BG 2016년 11월 26일
Moe
the weight function that you may be asking for is the shape of
w=randperm(numel(nA))/sum(nA)
this w is only an example, but the key point you need to have in the weight vector is
sum(w)
=
1
I understand that because you add time dependency to the weight vector w, this is going to change, so fast does w change?
John BG
  댓글 수: 2
Moe Joe
Moe Joe 2016년 11월 26일
편집: Moe Joe 2016년 11월 26일
No dear, t is not time, it refers to the number of errors in the Victor of length n. The idea is to generate a Victor of length n, and weight t. The answer of Walter is perfect. I appreciate both of you.
John BG
John BG 2016년 12월 1일
good to know, next time please give all question related in one go, not by instalments, will you?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by