MATLAB: How to use a function that is not in the same folder as your current folder

addpathfolderfunction

The situation is: I have made a function 'isittrue.m'. I save this function somewhere, unknown, on my pc (or I give this .m file to a friend). In my script, I want to use this function, so I want to check in my script where this function is saved on my pc (or on my friend's pc) and then make this function usable (independent on the location of this function). The current folder has to remain the same, because I use data from this folder.
How do I do this?

Best Answer

That is exactly what the MATLAB path is for: change the MATLAB path to include the folder where that file is saved.
"The current folder has to remain the same, because I use data from this folder."
That is a really bad reason to run code in a particular folder. Once you start using relative and absolute paths then you have no restriction on where the data needs to be. All MATLAB functions that accept filenames also accept absolute filenames, so there is no excuse not to use them.