フィルターのクリア

How do I import multiple csv files?

2 ビュー (過去 30 日間)
Adam
Adam 2012 年 10 月 11 日
Hi,
I have multiple csv files to import. To start with I followed the Matlab example for importing multiple text files, which is found in the documentation. However I have an error message that pops up:
Error in importfile (line 17)
delimiter = {',',' '};
Output argument "data" (and maybe others) not assigned during call to "filepath"
The csv files are named from S500D.csv to S593D.csv but there are only 82 files (not the 93 you might expect) which means that the file names are not necessarily in sequence. The files contain date and time data as well as numerical and require comma and space delimitation.
How can I import these files into Matlab into a cell array as in the Matlab example?
Thanks
Adam
  1 件のコメント
per isakson
per isakson 2012 年 10 月 11 日
編集済み: per isakson 2012 年 10 月 11 日
If nothing else works TEXTSCAN will - if all data rows have identical format.
BTW: A csv-file does not have two list delimiters.

サインインしてコメントする。

回答 (1 件)

Matt Tearle
Matt Tearle 2012 年 10 月 19 日
If the files all have the same format, and you have access to a recent version of MATLAB (12b would be nice...), use the Import Tool to do it interactively, then generate the code. Then apply the generated function to all the files.
You can use ls or dir to get an array of file names, then loop through that:
fnm = cellstr(ls('*.csv'));
for k = 1:length(fnm)
x = myimportfunction(fnm{k});
% do stuff with x
end
If you don't have the shiny new Import Tool, you could (a) upgrade :) or (b) use csvread or textscan, but you'd need to show the format of your file for us to be able to give much further guidance.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by