How do I write a script for a GUI.m file that allows me to press a button, choose a (*.csv) file and then copy this (*.csv) file to the current folder so it can be used for an existing simulation?

2 ビュー (過去 30 日間)
I already have a pushbutton that when pressed allows me to browse for a (*.csv) file. I tried the copyfile function as follows but get an error:
[filename, pathname, filerindex] = uigetfile('*.csv');
[success,message,messaageid] = copyfile(pathname,'A:\',filename);
A:\ is a mapped network drive.
I get the following error: Error using copyfile 'Data1.csv' is an invalid option string.
My code for the pushbutton in the GUI.m file is:
% --- Executes on button press in cmd_getDir.
function cmd_getDir_Callback(hObject, eventdata, handles)%****BROWSE button
[filename, pathname, filerindex] = uigetfile('*.csv'); %Get file
[success,message,messaageid] = copyfile('pathname','A:\',filename);%Need to copy file to current folder
assignin('base','FileCSV',filename); %assign the name FileCSV to the file
set(handles.text_directory,'String', filename); %Put filename in string space
% hObject handle to cmd_getDir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I understand from the MATLAB help that:
[SUCCESS,MESSAGE,MESSAGEID] = copyfile(SOURCE,DESTINATION,'f') attempts to copy SOURCE to DESTINATION, as above, even if DESTINATION is read-only. The status of the writable attribute of DESTINATION will be preserved.
SOURCE: 1 x n string, defining the source file or directory.
DESTINATION: 1 x n string, defining destination file or directory. The default is the current directory.
MODE: character scalar defining copy mode.
'f' : force SOURCE to be written to DESTINATION. If omitted, copyfile respects the current writable status of DESTINATION.


Matt Fig
Matt Fig 2012 年 12 月 13 日
編集済み: Matt Fig 2012 年 12 月 13 日
You need to make complete pathnames. One way to do it is to concatenate the output from UIGETFILE and also to concatenate the destination directory with the filename.
[filename, pathname, filerindex] = uigetfile('*.csv');
[S,M,MI] = copyfile([pathname,filename],['A:\',filename]);

その他の回答 (0 件)


Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by