Borrar filtros
Borrar filtros

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?

3 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Matt Fig
Matt Fig el 13 de Dic. de 2012
Editada: Matt Fig el 13 de Dic. de 2012
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]);

Más respuestas (0)


Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by