Undefined function or variable 'cvx_begin'

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 件のコメント

Adam Danz
Adam Danz 2018 年 7 月 16 日
Please format your code so it can be copied, pasted, and examined. The idea here is to make as little work as possible for the people who are eager to help you.
Without looking at the code, I can say that your script is trying to execute a command named 'cvx_begin' and there is no variable in your work space named that and there is no function on your matlab path named that either.
Adam
Adam 2018 年 7 月 16 日
編集済み: Adam 2018 年 7 月 16 日
Is it your code or someone else's? If it is yours then what do you expect cvx_begin to be? Why do you expect the code to know of it if you haven't defined it?
cvx_begin quiet
is a meaningless line. What is it supposed to be doing?
Van Vy
Van Vy 2018 年 7 月 17 日
編集済み: Van Vy 2018 年 7 月 17 日
@Adam Danz: Thank you for suggesting. I wonder that why the code look so ugly even I edit many time. I know the reason already :)
@Adam This code I take from internet. The source here: http://web.cvxr.com/cvx/examples/html/nonneg_matrix_fact.html I'm a newbie, i can not code by myself yet, need to see and try to run code for testing. Because my topic is related with matrix factorization. Can you give a help?

サインインしてコメントする。

 採用された回答

Steven Lord
Steven Lord 2018 年 7 月 16 日

0 投票

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 件のコメント

Van Vy
Van Vy 2018 年 7 月 17 日
Oh, really. It sounds good. I will try to find the toolbox. Thank you :)
Adam Danz
Adam Danz 2018 年 7 月 17 日
編集済み: Adam Danz 2018 年 7 月 17 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2018 年 7 月 16 日

編集済み:

2018 年 7 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by