Generate a random binary matrix with given rank by using minimum number of 1s

9 views (last 30 days)
Hi,
I am generating a random binary matrix with size ky x w with rank min(ky,w) with the code given below. However, because I am not constraining the possibility to select 0 or 1 as an element of a matrix, number of 0s and 1s are almost equal to each other. I need to create this matrix with rank min(ky,w) using minimum number of 1s. How can I achieve this, any suggestion?
k = 5;
y = 20;
w = 104;
A = randi([0 1], k*y, w);
while gfrank(A) ~= min(k*y, w)
A = randi([0 1], k*y, w);
end

Accepted Answer

Efe Berkay Yitim
Efe Berkay Yitim on 16 Feb 2023
Found a way:
k = 5;
y = 20;
w = 104;
p = 0.2;
A = randsrc(k*y, w, [0,1;1-p p]);
while gfrank(A) ~= min(k*y, w)
A = randsrc(k*y, w, [0,1;1-p p]);
end

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!