Hankel matrix, random entries

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 Kommentare

Dyuman Joshi
Dyuman Joshi am 8 Apr. 2023
Bearbeitet: Dyuman Joshi am 8 Apr. 2023
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}
ans = 2×2
1 2 2 1
omega{2}
ans = 4×2
1 4 2 3 3 2 4 1
thank you so muchy your way works nicely but I want to generate your way for any random sampling , so instead of ind=[2 4] , i wrote like the following, however the run is not stop i dont no the reason
m=n;
mn=m*n;
n=1000;
d=0.4;
r=10;
ok=0;
z=rot90(reshape(1:mn,n,n));
while ~ok
%Antidiagonals
%ind=[1:2*n-1]
ind=randperm((2*n)-1), round(((1-d)*(2*n)-1)/10);
%ctr=min(ind,2*n-ind);
Omega=cell(1,numel(ind));
for k=1:numel(ind)
[s,c]=ind2sub([n n],diag(z,ind(k)-n));
Omega{1,k}=[s c];
end
Omega=sub2ind([m n],s,c)
%Include the indices
[I,J] = ind2sub([m n],Omega)
Phi = sparse(I,J,1,m,n)
sumr = full(sum(Phi,1))
sumc = full(sum(Phi,2))
if any(sumr < r) || any(sumc < r)
disp('no')
continue
else
ok=1;
end
end
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)
ind = 1×1999
1138 523 1858 604 1644 639 170 1933 801 1147 1753 737 754 393 1710 1800 709 449 544 1295 657 444 249 888 1681 1642 1542 1404 1626 1602
ans = 120
%Corrected
ind=randperm((2*n)-1, round(((1-d)*(2*n)-1)/10))
ind = 1×120
1308 1849 1094 764 1949 1723 3 445 439 1404 341 753 331 358 846 1377 226 79 1929 155 1786 481 1348 98 419 276 755 1092 1053 664
I don't understand this line -
Omega=sub2ind([m n],s,c)
Why are you over-writing Omega just after the loop?
Hajar Alshaikh
Hajar Alshaikh am 9 Apr. 2023
because if I delete this step I got this error :Operator '-' is not supported for operands of type 'cell'.
Error in ind2sub (line 45)
vi = rem(ndx-1, siz(1)) + 1;
Dyuman Joshi
Dyuman Joshi am 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
Hajar Alshaikh am 9 Apr. 2023
I want omega to be as indices not as cells
Will this be acceptable?
%Input
ind = [2 4];
%Output
Omega = [1 2;
2 1;
1 4
2 3
3 2
4 1];
Hajar Alshaikh
Hajar Alshaikh am 9 Apr. 2023
no i want ind to be random not only the second and fourth, because i will use it for large data size such what i said n=1000
Dyuman Joshi
Dyuman Joshi am 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
Hajar Alshaikh am 9 Apr. 2023
i want the indices stored as 1×n matrix as the output
Hajar Alshaikh
Hajar Alshaikh am 9 Apr. 2023
i am not that much good with matlab, i dont know if you understand what i want correctly or not

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Gefragt:

am 8 Apr. 2023

Kommentiert:

am 9 Apr. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by