Creating random binary 3D matrix with specified rank

4 views (last 30 days)
I need to create k number of n by m binary matrixes (lets call each of them Hᵢ where i from 1 to k) where for each of these matrixes their rank should be equal to m. Therefore, rank(Hᵢ) = m.
I think I can create them by using (not sure):
function [Y,rk] = generateMatrix(w,y,rank)
P = orth(randi([0 1], w, rank));
Q = orth(randi([0 1], y, rank))';
Y = P*Q;
rk = rank(Y);
end
Now, I want to achieve rank(H꜀) = min(n, k*m) where H꜀ = [H₁ H₂ ... Hₖ].
How can I achieve this?
Thanks

Answers (1)

Gayatri Rathod
Gayatri Rathod on 1 Mar 2023
Hi Efe Berkay,
  • To achieve a rank of Hc equal to min (n, k*m), where Hc is the horizontal concatenation of the k binary matrices H₁, H₂, ..., Hₖ, you can modify the generateMatrix function to generate matrices with a desired rank as follows:
function [Y,rk] = generateMatrix(w,y,rank)
P = orth(randi([0 1], w, rank));
Q = orth(randi([0 1], y, rank))';
Y = P*Q;
Y = Y (:, 1:min(size(Y))); % truncate to desired rank
rk = rank(Y);
end
  • This modified function generates a binary matrix Y of size w by y with rank equal to the specified rank. Then, it truncates the matrix Y to the first min (w, y, rank) columns, ensuring that the resulting matrix has the desired rank.
  • To generate k matrices H₁, H₂, ..., Hₖ with rank equal to m, you can call the modified generateMatrix function in a loop:
n = 10; % size of each matrix
m = 3; % desired rank of each matrix
k = 4; % number of matrices to generate
H = zeros(n, m*k); % initialize H
for i = 1:k
% generate a matrix Hi with rank m
[Hi, ~] = generateMatrix(n, m*k, m);
% add Hi to H
H(:, (i-1)*m+1:i*m) = Hi;
end
% check rank of H
rk = rank(H);
rk_desired = min(n, k*m);
fprintf('Rank of H: %d (desired rank: %d)\n', rk, rk_desired);
  • This code generates k binary matrices H₁, H₂, ..., Hₖ with rank equal to m, and concatenates them horizontally to form the matrix H. The rank of H is then checked to ensure that it is equal to the desired rank of min(n, k*m).
You can read more about the rank function from the following documentation: rank Function.
Hope it helps!
Regards,
Gayatri Rathod

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!