It is likely better to use the fullfile function than to cd to the path.
I would define ‘keyfile’ as:
keyfile = fullfile(pathname, filename);
and completely remove the cd calls.
If you hare having problems finding the file, You will have to use the operating system to find it if it is not on your MATLAB search path. In Windows, this is the File Explorer utility.