Nuclear norm coding issue

4 次查看(过去 30 天)
Karim Wahdan
Karim Wahdan 2021-2-16
So I have a Nuclear norm program thats supposed to output a graph but my issue is that when ever I decide to make the dimensions n and m smaller than 30 and 30 the code gives this error message and gives out a graph that isnt fully correct.
Following error message -
Index exceeds the number of array elements (3).
Error in Untitle234d (line 131)
plot([1 : 50:(m*n)], SuccessRate(2:9));
Here is my code
% Number of Monte Carlo simulations
MC = 10;
% Fix the dimentions of a groundtruth table X*
n = 10; m = 10;
% Fix the rank of k
k = 3;
% Use (41) to generate X*
U = randn(m, k); V = randn(n, k);
X = U*V';
% Define the success threshold(epsilon) and initialise variables for
% calculating the success rates
epsilon = 0.2;
CountS = 0; CountT = 0;
SuccessRate = 0;
for p = 1 : 50 : (m*n) % Number of observations
for mc = 1 : MC % Monte Carlo simulations
M_p = cell(p, 1); % Cell array of empty matrices
y = zeros(p, 1); % Vector of measurements
for i_p = 1 : p % Generate measurement matrices in the cell array
% Get e_i
rp_i = randperm(m);
% Generate a vector of random values
e_i = zeros(m, 1);
e_i(rp_i(1)) = 1;
% Generate e_i as a vector of zeros with a single 1 at a random index
% Get e_j
rp_j = randperm(n);
e_j = zeros(n, 1);
e_j(rp_j(1)) = 1;
% Get the M matrix
M_p{i_p} = e_i .* e_j';
y(i_p) = trace(M_p{i_p}*X);
end
cvx_begin % (48)
variable Xe(n,n);
minimize(norm_nuc(Xe));
subject to
for i_p = 1 : p
trace(Xe*M_p{i_p}) == y(i_p);
end
cvx_end
end
% If the recreation was successful, increment the success counter
if ((norm(Xe-X, 'fro')/norm(X, 'fro')) <= epsilon)
CountS = CountS + 1;
end
% Increment the trial counter
CountT = CountT + 1;
% Define the success rate for the current p value
SuccessRate = [SuccessRate (CountS/CountT)];
end
% Plot the success rate as a fuction of p. Then, on the same axes, plot the
% line @ p0 = 3k(m + n - k) + 1
hold on
plot([1 : 50:(m*n)], SuccessRate(2:9));
p0 = 3*k*(m + n - k) + 1;
xline(p0);
hold off;

回答(1 个)

Image Analyst
Image Analyst 2021-2-16
In
plot([1 : 50:(m*n)], SuccessRate(2:9))
SuccessRate(2:9) has 8 elements. Does x have 8 elements? What does this show
lengthX = length([1 : 50:(m*n)]);
If it's not 8, it won't work. What does it give for lengthX?

类别

Help CenterFile Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by