MATLAB: How to make a user defined function with the input being the file name in a string

user defined function

I want to make a user defined function where the user can just type in the file name as the input. For example, if my file is called 'graphs.csv' and my function is called power, I want to be able to do
power('graphs.csv') and for the function to run. How do I make this as my input?

Best Answer

Sure, this is easy (do NOT use the name power, as this is already used by MATLAB):
function myfun(filename)
data = csvread(filename);
...
end
and call it like this:
myfun('graphs.csv')
How to define functions is clearly explained in the function help.