Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Importing .xlsx files in parallels
Replies: 8   Last Post: Mar 10, 2013 10:46 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
ryanshuell@gmail.com

Posts: 128
Registered: 2/11/08
Re: Importing .xlsx files in parallels
Posted: Mar 9, 2013 9:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

So, the last code sample that I posted will loop through several Excel files in a folder, and import each Excel file into a separately matrix for each, respectively.

A while back I tried to figure out a way to import several Excel files in a folder, and basically concatenate all files into one single matrix in Matlab, sort of like a Union Query in a database. Well, I never figured out how to do that in Matlab, but you can run the VBA code in the links below to do that in Excel, and then read that one large (concatenated) file into Matlab.

Here's the links:
http://www.rondebruin.nl/copy3.htm
http://www.rondebruin.nl/fso.htm
http://www.rondebruin.nl/merge.htm


"Ryan" wrote in message <khef06$2c0$1@newscl01ah.mathworks.com>...
> Sorry, but it looks like the last M-code sample that I posted does NOT import all Excel files in a folder. Well, at least I couldn't get it to work. This, however, does work.
>
> % % Import all excel files in a folder into multiple Matlab variables.
> % % Your variables will be num1, num2, ...etc
> d = dir('C:\Users\Ryan\Desktop\Excel_Files\*.xls*');
> nfiles = length(d);
> for k = 1:nfiles
> n=int2str(k);
> eval(['[num' n ', txt' n ', raw' n '] = xlsread(d(k).name,1);']);
> end
>
>
>
>
> "Ryan" wrote in message <khdg08$80a$1@newscl01ah.mathworks.com>...

> > Run this code to convert all .XSLX files in a specific folder, of your choosing, to .XSL files.
> >
> > Sub Convert_xls_Files()
> >
> > Dim strFile As String
> > Dim strPath As String
> >
> > With Application
> > .EnableEvents = False
> > .DisplayAlerts = False
> > .ScreenUpdating = False
> > End With
> > 'Turn off events, alerts & screen updating
> >
> > strPath = "C:\Users\rshuell\Desktop\Excel_Files\"
> > strFile = Dir(strPath & "*.xls")
> > 'Change the path as required
> >
> > Do While strFile <> ""
> > Workbooks.Open (strPath & strFile)
> > strFile = Mid(strFile, 1, Len(strFile) - 5) & ".xls"
> > ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:=xlOpenXMLWorkbook
> > ActiveWorkbook.Close True
> > strFile = Dir
> > Loop
> > 'Opens the Workbook, set the file name, save in new format and close workbook
> >
> > With Application
> > .EnableEvents = True
> > .DisplayAlerts = True
> > .ScreenUpdating = True
> > End With
> > 'Turn on events, alerts & screen updating
> >
> > End Sub
> >
> > Try to import the .XLS files into your Matlab.
> >
> >
> >
> > You won't be able to load them all at once but you could easily use a for-loop to process them one at a time. Something like this:
> >
> > source_dir = 'path/to/source/'
> > dest_dir = '/path/to/dest'
> > source_files = dir(fullfile(source_dir, '*.xls'));
> > for i = 1:length(source_files)
> > data = xlsread(fullfile(source_dir, source_files(i).name)));
> > #do something with data
> > xlswrite(fullfile(dest_dir, source_files(i).name)));
> > end
> >
> >
> >
> > "Ryan" wrote in message <khdf9n$5pf$1@newscl01ah.mathworks.com>...

> > > I hate Macs so much!! What exactly is the problem? You need to convert a bunch of XLSX files to XLS files b/c you don't have Matlab 2012a? I can crate an Excel Macro for you to go into all XLSX files in a specific folder, and convert all files to XLS files. Will that do it for you?
> > >
> > > Regards,
> > > Ryan--
> > >
> > > Gadi Reinhorn <greinhorn@mathworks.com> wrote in message <5130E273.8090508@mathworks.com>...

> > > > The functionality you need was added in R2012a:
> > > > http://www.mathworks.com/help/releases/R2012a/techdoc/rn/bs7oakc-1.html#btau8hq
> > > >
> > > > xlsread Reads XLSX Files on All Platforms
> > > >
> > > > The xlsread function now reads data from XLSX files on all platforms,
> > > > including support for specifying the range and worksheet number.
> > > > Previously, this functionality was available only on Microsoft Windows
> > > > systems with Excel® software.
> > > >
> > > >
> > > > Gadi




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.