Hankel matrix, random entries
Show older comments
i have a hankel matrix X:
row1 = 1:n;
col1 = (n+1):(2*n-1);
% Create the full-rank Hankel matrix of size n^2
H_full = hankel(row1, col1);
% Compute the low-rank approximation
[U,S,V] = svd(H_full);
U = U(:, 1:r);
S = S(1:r, 1:r);
V = V(:, 1:r);
X = U*S*V';
and i want to select random anti digonals and let them in a set called omega
for example i have 5×5 matrix and I want to choose two random anti diagonals and let the indices of the entries belong to these inside a set called omega . so in the 5 by 5 matrix there are 9 anti diagonal and i want to choose second and fourth antidiagonals so omega ={(1,2),(2,1),(1,4),(2,3),(3,2),(4,1)}
11 Comments
There are undefined variables in your code.
n=5;
row1 = 1:n;
col1 = (n+1):(2*n-1);
% Create the full-rank Hankel matrix of size n^2
H_full = hankel(row1, col1);
H_full is not of size nxn, as col1 has n-1 elements. If you want H_full of size nxn, change
col1 = (n+1):(2*n);
Getting indices of anti-diagonals
z=rot90(reshape(1:n^2,n,n));
%Antidiagonals
ind=[2 4];
%ctr=min(ind,2*n-ind);
omega=cell(1,numel(ind));
for k=1:numel(ind)
[r,c]=ind2sub([n n],diag(z,ind(k)-n));
omega{1,k}=[r c];
end
omega{1}
omega{2}
Hajar Alshaikh
on 9 Apr 2023
There's a paranthesis mis-match in defining 'ind' and thus you get 2 output from that line
n=1e3;d=0.4;
% |
% v
ind=randperm((2*n)-1), round(((1-d)*(2*n)-1)/10)
%Corrected
ind=randperm((2*n)-1, round(((1-d)*(2*n)-1)/10))
I don't understand this line -
Omega=sub2ind([m n],s,c)
Why are you over-writing Omega just after the loop?
Hajar Alshaikh
on 9 Apr 2023
Dyuman Joshi
on 9 Apr 2023
What exactly do you want to do with Omega? Say you get Omega after the for loop, how do you want to use it?
I can't comment on the error as I do not have enough information.
Hajar Alshaikh
on 9 Apr 2023
Dyuman Joshi
on 9 Apr 2023
Will this be acceptable?
%Input
ind = [2 4];
%Output
Omega = [1 2;
2 1;
1 4
2 3
3 2
4 1];
Hajar Alshaikh
on 9 Apr 2023
Dyuman Joshi
on 9 Apr 2023
I know you want "ind" to be random, but I presented a sample example. You are focusing on the literal values rather than the format of the output.
Are the indices stored as a nx2 matrix acceptable as the output?
Hajar Alshaikh
on 9 Apr 2023
Hajar Alshaikh
on 9 Apr 2023
Answers (0)
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!