MATLAB: How to get the only variable in file .mat autoumaticly

automatic;loadvector

hello,
i am developping a function where i need a vector this one is going to be in a file .mat ,and in my function i can only call the file .mat.
Function FAngle(vectorfile)
load(vectorfile);
FAmax=max(vectorfile)
end
wha i want is getting the max value of my vector wich is in the file , so when i do like this i got a false value.i thinnk it is a value of the file structure and not the value of the vector in this file .mat
thank you for your help

Best Answer

Your function signature is incomplete. Hopefully, you do know how to write a function properly.
function FAmax = somename(vectorfile)
%function documentation goes here
%vectorfile: full path of mat file to load. The mat file must contain one variable only, and this variable must be a vector
%FAmax: maximum value of the vector stored in the mat file.
matcontent = load(vectorfile); %load mat file into a structure. Each field of the structure is a variable of the mat file. See load documentation
varnames = fieldnames(matcontent); %get names of variables
assert(numel(varnames) == 1, 'MAT file contains more than one variable');
FA = matcontent.(varnames{1});
assert(isvector(FA), 'The variable in the mat file is not a vector');
FAmax = max(FA);
end