I have created a function called firstcol.m. The function returns the first column of the input matrix.
function B = firstcol(A);B = A(:,1);
I saved this MATLAB file to "../my_work/@gf/" directory. I have added the path "../my_work/" to the MATLAB search path. When I type the following code in the MATLAB command window:
A = gf(randint(5,5,[0,15]),4)B = firstcol(A)
it returns the entire matrix A except for the first column.
If I modify the function to the following and test the same code in the MATLAB command window, it returns the first column of A correctly.
function B = firstcol(A);B = subsref(A, substruct('()', {':',1}));
Best Answer