How to minimize a new function defined by myself

if I define a target function fun(x) in matlab file fun.m , how can I use cvx to minimize the function. It seems wrong by simply writing the code like:

%%%%%% fun.m

y=fun(x)

y=x.^2

%%%%%% cvx

cvx_begin

variable x

minimize( fun(x) )

cvx_end

Even such a simple function fails to run.
Can anyone give me some details about how to define a new function (convex of course) and use cvx to minimize it? Thanks!