MATLAB: Matrix function “Index exceeds matrix dimensions”

errorfunctionindexmatrix

I'm trying to create a function that will plot a column of data. However when I plug in the value of the column it returns an error and I cannot see why? Here's my code:
function y = myplot(x)
global data; % 40:40 matrix created in a separate M-file
y = plot(data(:,x)); %Function is supposed to plot all the rows of a certain column
Whenever I test this function in the command window it returns an error that says "Index exceeds matrix dimensions". It also will not run as it "requires more input arguments". How can I fix this?

Best Answer

Your array data has not been initialized as global in some other function.