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

2 次查看(过去 30 天)
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

采纳的回答

Efe Berkay Yitim
Efe Berkay Yitim 2023-2-16
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by