Q:

Matlab Matrix inner dimension must agree

I have a simple quadratic form function. 
function [y, grady] = quadobj(x)
global Q
y = x*Q*x';
if nargout > 1
    grady = 2*Q*x;
end

When I simply calculate the quadratic form on the command line, it works.
>> [1 1 1]*Q*[1 1 1]'

ans =

   -2.5977

>> Q

Q =

   -1.0000   -0.0731    0.3043
   -0.0731   -1.0000   -0.0300
    0.3043   -0.0300   -1.0000

But when I try to evaluate the function, I get an error
>> quadobj([1 1 1])
Error using  * 
Inner matrix dimensions must agree.

Error in quadobj (line 3)
y = x*Q*x';

3   y = x*Q*x';

Why is this behavios occuring? It seems to me that the dimensions line up in the way I have written line three of the quadratic form function. Please help!

A:

The reason is, that Q is not globally available from the workspace (and is automatically interpreted as 0x0 double matrix instead).
global Q;
Q = rand(3);
quadobj([1,1,1])

will do the job.
Note: Next time you can easily find that by using the debugger.

