Undefined function or variable 'cvx_begin'
59 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Van Vy
el 16 de Jul. de 2018
Hi everyone! I'm trying to understand how does matlab work with the matrix factorization which related to my task now. I used this code to test for matrix factorization. And the code dont run because of a function. The warning told that: "Undefined function or variable 'cvx_begin'". What should I fix it? Have any professional matlaber help me? Thank you in advance. Here is my code:
% Generate data matrix A
rstate = rand();
m = 10; n = 10; k = 5;
A = rand(m,k)*rand(k,n);
% Initialize Y randomly
Y = rand(m,k);
% Perform alternating minimization
MAX_ITERS = 30;
residual = zeros(1,MAX_ITERS);
for iter = 1:MAX_ITERS
cvx_begin quiet
if mod(iter,2) == 1
variable X(k,n)
X >= 0;
else
variable Y(m,k)
Y >= 0;
end
minimize(norm(A - Y*X,'fro'));
cvx_end
fprintf(1,'Iteration %d, residual norm %g\n',iter,cvx_optval);
residual(iter) = cvx_optval;
end
% Plot residuals
plot(residual);
xlabel('Iteration Number');
ylabel('Residual Norm');
% Display results
disp( 'Original matrix:' );
disp( A );
disp( 'Left factor Y:' );
disp( Y );
disp( 'Right factor X:' );
disp( X );
disp( 'Residual A - Y * X:' );
disp( A - Y * X );
fprintf( 'Residual after %d iterations: %g\n', iter, cvx_optval );
3 comentarios
Respuesta aceptada
Steven Lord
el 16 de Jul. de 2018
The cvx_begin function is not from any MathWorks-provided toolbox. I believe that it's part of this toolbox. You will need to download and install that toolbox to use that function.
2 comentarios
Adam Danz
el 17 de Jul. de 2018
Editada: Adam Danz
el 17 de Jul. de 2018
After you download the toolbox to your Matlab folder you'll have to make sure that the directory that stores the toolbox is on your Matlab path.
Judging from the code you provided, there might be additional problems so feel free to return for help.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!