Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Efe Berkay Yitim
Efe Berkay Yitim le 16 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by