MATLAB: XLSWRITE – into same folder location as M file

xlswrite

I want to store my M files on a USB stick for protability. Some of these M files create xlsx files as an output. I would like to store these in the same folder location as the M file which creates them. I used the usual xlswrite ('filename.xlsx', variable); but get an error:
Error using xlswrite (line 220)
Invoke Error, Dispatch Exception:
Source: Microsoft Excel Description: Microsoft Excel cannot access the file 'C:\WINDOWS\system32\38C41000'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Many thanks.

Best Answer

Thanks guys for your attempts. Your help is most appreciated.
I eventually stumbled upon the "uigetfile" instruction as with just a one click on the m file of interest in a folder, and the uigetfile picks up the folder + filename. I then stripped the filename and retained the folder.