You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: matrix_completion_squared_error.m
    path of file: ./repos/Projects/Optimization/ConditionalGradientMethod/Frank Wolfe and Greedy Optimization for Learning with Big Data - MATLAB Code
    
    the code of the file until where you have to start completion: function [f,g] = matrix_completion_squared_error(X,Y)
% Matrix completion squared error objective:
%  min_X (1/2)(X(Y~=0) - Y(Y~=0))^2

[rows,cols,vals] = find(Y);

% Compute objective

    
function [f,g] = matrix_completion_squared_error(X,Y)
% Matrix completion squared error objective:
%  min_X (1/2)(X(Y~=0) - Y(Y~=0))^2

[rows,cols,vals] = find(Y);

% Compute objective
preds = X(Y~=0);
M = preds - vals;
f = sum(M(:).^2)/2;

if nargout > 1
    % Compute gradient
    g = sparse(rows,cols,M);
end