I suspect you are pressing the "Run" button with your function file open.
Your function needs to return the final value as an output argument. So first off, change the function file to this and save it as a separate file named mystaff.m:
function meanp = mystaff(S)
error('This program takes one input matrix argument')
error('S must be scalar')
pmat = S >= 140000;
p = S(pmat)
meanp = mean(p)
To call your function, make a new script and put your code to be executed in that script. From what you've shown, it would be like this:
filename = 'Salaries.xlsx';
S = xlsread('Salaries.xlsx')
meanp = mystaff(S);
Let us know if this works for you or what further issues you are encountering.