MATLAB: Importing a csv file into matlab automatically after it gets changed

matlab import file

I have .csv file on my desktop which get replaced. I want to use a command in matlab which imports this file every time it gets changed into matlab for calculations. I got this formula:
fsw = System.IO.FileSystemWatcher();
fsw.Path = 'C:\Users\wolfx\Desktop';
fsw.Filter = 'filename.csv';
fsw.EnableRaisingEvents = true;
listenerhandle = addlistener(fsw, 'Changed', importfcn);
%signature of importfcn is function importfcn(sender, eventargs)
%add a small delay in importfcn before reading the file as the event is raised
%to make sure that file modification is complete
This formula gives me the error Undefined function or variable 'importfcn'.
Can anyone give me a hint or a site where I can read more about this?
thanks

Best Answer

The errror is because when you just type "importfcn" it is attempting to RUN importfcn. What you're trying to do is tell the addlistener function "the NAME of the function i want you to run is "importfcn". You do this with the @ symbol. Thus you want:
listenerhandle = addlistener(fsw, 'Changed', @importfcn);