MATLAB: Error using copyfile from a changing directory

charactercopyfileerrormovefilepwdstring

I am pulling a file to read in from an always changing directory. I would like to copy this file into a directory I have it for storage and further data analysis.
this_folder = pwd
[data, path] = uigetfile('*csv')
data2 = fullfile(path, data)
do some processing then when I am finished
f_all = fullfile(this_folder, 'data_plots\All_data_plots')
copyfile(data,f_all)
I get the error:
Error using copyfile
Argument must contain a string
The problem is data, data2, f_all, path, and this_folder are all characters so I am not sure what it means by must contain a string.

Best Answer

If the user cancels uigetfile() then the file output (which you call "data") will return a numeric value rather than a character.
If you use uigetfile() with Multiselect turned on, then the file output will return as a cell array of strings, even if only one value is chosen by the user.