MATLAB: Script not finding variable even when the variable is in the workspace

scriptvariable

So I have a bunch of variables from a data file in my workspace and I'm making a script to plot a contour plot quickly and it works fine.
function contf(A,B,C)
a=min(A):(max(A)-min(A))/200:max(A);
b=min(B):(max(B)-min(B))/200:max(B);
[Aq,Bq]=meshgrid(a,b);
C=griddata(A,B,C,Aq,Bq);
contourf(Aq,Bq,C)
set(gca,'YDir','reverse');
set(gca,'xaxislocation','top');
end
However A and B are always X and Y, variables that are in my respectively in my workspace. When i try this shorter function its not working?
function qcontf(C)
A=X
B=Y
a=min(A):(max(A)-min(A))/200:max(A);
b=min(B):(max(B)-min(B))/200:max(B);
[Aq,Bq]=meshgrid(a,b);
C=griddata(A,B,C,Aq,Bq);
contourf(Aq,Bq,C)
set(gca,'YDir','reverse');
set(gca,'xaxislocation','top');
end
I just get
Undefined function or variable 'X'.
Error in qcontf (line 2) A=X

Best Answer

The variables X and Y in your workspace are not known inside the function. You can use the following, but it's not considered good practice:
function qcontf(C)
global X
global Y
A=X
B=Y