How to import csv files in Matlab?

4 visualizzazioni (ultimi 30 giorni)
Onihime
Onihime il 14 Nov 2015
Modificato: Stephen23 il 14 Nov 2015
I would like to import data from csv files from the folder. I used to "import data", but there is no possibility to import more than one file. So I want to remodel script which was generated by "import data". I have about 10-15 csv files in the folder. How can I do this? Give me any advice on importing the CSV files. Thank you. There is script generated by Matlab:
%%Initialize variables.
filename = 'C:\...\laser 1\1km\TRACE904.CSV';
delimiter = ',';
startRow = 14;
%%Format string for each line of text:
formatSpec = '%f%f%*s%[^\n\r]';
%%Open the text file.
fileID = fopen(filename,'r');
%%Read columns of data according to format string.
textscan(fileID, '%[^\n\r]', startRow-1, 'ReturnOnError', false);
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
%%Close the text file.
fclose(fileID);
%%Create output variable
TRACE904 = [dataArray{1:end-1}];
%%Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;

Risposte (1)

Stephen23
Stephen23 il 14 Nov 2015
Modificato: Stephen23 il 14 Nov 2015
Reading multiple files is such a common topic that it is covered very well on our Wiki:
And currently there are more than seven hundred threads on this forum when I search for "read CSV". Did you read any of them?:
Also the documentation contains lots of hints and advice, which you can browse using the contents panel:

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by