Thread Subject: Importing several CSV files at the same time (600 or more)

Subject: Importing several CSV files at the same time (600 or more)

From: BO

Date: 1 Oct, 2007 15:30:55

Message: 1 of 6

Hey! i need to import around 400-600 csv files to the workspace at the same time so i can take the data in those file and graph it, the issue is that i have to this trough a Gui, and using uiimport takes a lot of time. Is there a way that i can import that many files, and let the user of the gui select de directory and the number of files.
type of files: CSV files, with 3 colums each colum a variable with around 8192 points.

Subject: Importing several CSV files at the same time (600 or more)

From: G.A.M.

Date: 1 Oct, 2007 19:33:20

Message: 2 of 6

BO <bianca_osorio@hotmail.com> wrote in message
<5497789.1191252685630.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hey! i need to import around 400-600 csv files to the
workspace at the same time so i can take the data in those
file and graph it, the issue is that i have to this trough a
Gui, and using uiimport takes a lot of time. Is there a way
that i can import that many files, and let the user of the
gui select de directory and the number of files.
> type of files: CSV files, with 3 colums each colum a
variable with around 8192 points.

This code doesn't include a feature for limiting the number
of files in a directory, but you could add that easily:

%let user select directory from UI,
%and pass this directory as a parameter
function ProcessFiles(directory)
allFiles = dir(directory);
for k = 1 : length(allFiles)
if(strfind(allFiles(k).name, '.csv'))
processFile([directory '\' allFiles(k).name]);
end
end
end

Subject: Importing several CSV files at the same time (600 or more)

From: BO

Date: 2 Oct, 2007 12:53:01

Message: 3 of 6

Hey Thank u for ur answer.. i try the code u said.. just with the directory i want... to see what it does..
%let user select directory from UI,
%and pass this directory as a parameter
function ProcessFiles ('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
allFiles = dir('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
for k = 1 : 100(allFiles)
if(strfind(allFiles(k).name, '.csv'))
processFile([C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs '\' allFiles(k).name]);
end
end
end
 but i get this...
??? Error: File: ProcessFiles.m Line: 3 Column: 24
Missing MATLAB operator

Subject: Importing several CSV files at the same time (600 or more)

From: "G.A.M.

Date: 2 Oct, 2007 14:21:53

Message: 4 of 6

On Oct 2, 8:53 am, BO <bianca_oso...@hotmail.com> wrote:
> Hey Thank u for ur answer.. i try the code u said.. just with the directory i want... to see what it does..
> %let user select directory from UI,
> %and pass this directory as a parameter
> function ProcessFiles ('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
> allFiles = dir('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
> for k = 1 : 100(allFiles)
> if(strfind(allFiles(k).name, '.csv'))
> processFile([C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs '\' allFiles(k).name]);
> end
> end
> end
> but i get this...
> ??? Error: File: ProcessFiles.m Line: 3 Column: 24
> Missing MATLAB operator

I see several potential issues:
1. Did you write the function "processFile"?
2. The parameter to your main function (ProcessFiles) should probably
be: 'C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs'
3. You are missing the single quotes on your first parameter to
processFile.
4. your for-loop syntax looks incorrect.

Subject: Importing several CSV files at the same time (600 or more)

From: Dan Hensley

Date: 2 Oct, 2007 14:24:13

Message: 5 of 6

BO wrote:
> Hey! i need to import around 400-600 csv files to the workspace at the same time so i can take the data in those file and graph it, the issue is that i have to this trough a Gui, and using uiimport takes a lot of time. Is there a way that i can import that many files, and let the user of the gui select de directory and the number of files.
> type of files: CSV files, with 3 colums each colum a variable with around 8192 points.

This is a FAQ:

http://www.mit.edu/~pwb/cssm/matlab-faq.html#loopoverfiles

Dan

Subject: Importing several CSV files at the same time (600 or more)

From: Peter Boettcher

Date: 2 Oct, 2007 16:33:22

Message: 6 of 6

BO <bianca_osorio@hotmail.com> writes:

> Hey Thank u for ur answer.. i try the code u said.. just with the
> directory i want... to see what it does..

> %let user select directory from UI,
> %and pass this directory as a parameter
> function ProcessFiles ('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
> allFiles = dir('C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs\*.csv');
> for k = 1 : 100(allFiles)
> if(strfind(allFiles(k).name, '.csv'))
> processFile([C:\Users\Biankita\Documents\EQUIMAVENCA\DATA\RD04-1\FFTs '\' allFiles(k).name]);
> end
> end
> end
> but i get this...
> ??? Error: File: ProcessFiles.m Line: 3 Column: 24
> Missing MATLAB operator

You were not supposed to replace "directory" with your directory. It
was supposed to be a function which you called using your directory as
a parameter.

If you don't know what I am talking about, take a break from this task
and read the "Getting Started" part of the MATLAB documentation.

-Peter

Tags for this Thread

Everyone's Tags:

csv

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
csv Ned Gulley 2 Oct, 2007 11:42:47
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com