fopen function how to use a variable name to select a file present in a folder?

i have some csv files in a folder which i am trying to edit using matlab.
my code is below
yourfolder='D:\practice\Matlab\APM3 magnet measurements\Sensormagnet1';
d=dir([yourfolder '\*.csv']);
files={d.name};
file=files(1);
fid = fopen(file,'w');
files is a variable which has list of csv files present in folder. i created a variable to get one file name out of the list and trying to open the file with the name present in the file variable.
its giving error as given below:
Error using fopen
First input must be a file name of type char, or a file identifier of type double.
Error in CSV (line 5)
fid = fopen(file,'w');
please help me on this

 Réponse acceptée

Stephen23
Stephen23 le 2 Juin 2016
Modifié(e) : Stephen23 le 2 Juin 2016
The mistake is on this line:
file=files(1);
You need to use cell array indexing, then the code will work:
file = files{1};

Plus de réponses (0)

Catégories

En savoir plus sur Software Development Tools dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by