Thread Subject: xlsread

Subject: xlsread

From: Travis

Date: 13 Jan, 2009 23:12:02

Message: 1 of 7

I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.

[type, sheets] = xlsfinfo('raw data.xls')

for i=1:8
data=xlsread('raw data.xls',sheets{1})
end

This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?

Subject: xlsread

From: per isakson

Date: 14 Jan, 2009 00:27:02

Message: 2 of 7

"Travis" <sinusoid2@hotmail.com> wrote in message <gkj742$bej$1@fred.mathworks.com>...
> I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.
>
> [type, sheets] = xlsfinfo('raw data.xls')
>
> for i=1:8
> data=xlsread('raw data.xls',sheets{1})
> end
>
> This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?

Would something like this do it?

data = cell( 1, 8 );
for ii=1:8
data{ii}=xlsread('raw data.xls',sheets{ii})
end

/per

Subject: xlsread

From: Travis

Date: 16 Jan, 2009 17:12:01

Message: 3 of 7

"per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <gkjbgl$irm$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gkj742$bej$1@fred.mathworks.com>...
> > I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.
> >
> > [type, sheets] = xlsfinfo('raw data.xls')
> >
> > for i=1:8
> > data=xlsread('raw data.xls',sheets{1})
> > end
> >
> > This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?
>
> Would something like this do it?
>
> data = cell( 1, 8 );
> for ii=1:8
> data{ii}=xlsread('raw data.xls',sheets{ii})
> end
>
> /per


OK, that works great, thank you. Now do you know of a way for use xlswrite, and NOT get the default Sheet1, Sheet2, Sheet3?

Subject: xlsread

From: Travis

Date: 16 Jan, 2009 17:14:02

Message: 4 of 7

"per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <gkjbgl$irm$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gkj742$bej$1@fred.mathworks.com>...
> > I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.
> >
> > [type, sheets] = xlsfinfo('raw data.xls')
> >
> > for i=1:8
> > data=xlsread('raw data.xls',sheets{1})
> > end
> >
> > This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?
>
> Would something like this do it?
>
> data = cell( 1, 8 );
> for ii=1:8
> data{ii}=xlsread('raw data.xls',sheets{ii})
> end
>
> /per

Actually, looked at the data a little more, and while that does bring in all the data, there is are no tags on the data. Is there a way to bring the data in as individual variables?

Subject: xlsread

From: per isakson

Date: 17 Jan, 2009 05:40:03

Message: 5 of 7

"Travis" <sinusoid2@hotmail.com> wrote in message <gkqf8q$pkh$1@fred.mathworks.com>...
> "per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <gkjbgl$irm$1@fred.mathworks.com>...
> > "Travis" <sinusoid2@hotmail.com> wrote in message <gkj742$bej$1@fred.mathworks.com>...
> > > I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.
> > >
> > > [type, sheets] = xlsfinfo('raw data.xls')
> > >
> > > for i=1:8
> > > data=xlsread('raw data.xls',sheets{1})
> > > end
> > >
> > > This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?
> >
> > Would something like this do it?
> >
> > data = cell( 1, 8 );
> > for ii=1:8
> > data{ii}=xlsread('raw data.xls',sheets{ii})
> > end
> >
> > /per
>
> Actually, looked at the data a little more, and while that does bring in all the data, there is are no tags on the data. Is there a way to bring the data in as individual variables?

The full syntax reads:

    [num, txt, raw] = xlsread(filename, ...)

What do you mean by "tags"?

XLSREAD splits the contents of the sheet. Numerical data goes into num and text into txt. Be aware that num(1,1) might not refer to the same cell as txt(1,1). raw holds both numerical and text data. I guess you will find the "tags" in txt and raw.

No, I don't know how to avoid the default sheets, sheet1, ... . However, with the Ms COM-ActiveX-??-object you can do "everything". It might be worth searching the File Exchange.

/ per

Subject: xlsread

From: Travis

Date: 17 Jan, 2009 18:14:01

Message: 6 of 7

"per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <gkrqvj$bd6$1@fred.mathworks.com>...
> "Travis" <sinusoid2@hotmail.com> wrote in message <gkqf8q$pkh$1@fred.mathworks.com>...
> > "per isakson" <poi.nospam@bimDOTkthDOT.se> wrote in message <gkjbgl$irm$1@fred.mathworks.com>...
> > > "Travis" <sinusoid2@hotmail.com> wrote in message <gkj742$bej$1@fred.mathworks.com>...
> > > > I know there is a way to import seperate worksheets from an excel book into matlab as seperate variables, but I cannot remember how. I have the sheet names from using xlsfinfo, and can read them in individually, but I can't figure out how to get the in en-mass.
> > > >
> > > > [type, sheets] = xlsfinfo('raw data.xls')
> > > >
> > > > for i=1:8
> > > > data=xlsread('raw data.xls',sheets{1})
> > > > end
> > > >
> > > > This only gives me the last of the sheets (which is obvious because it keeps overwriting itself). How can I change 'data' with each itteration of i?
> > >
> > > Would something like this do it?
> > >
> > > data = cell( 1, 8 );
> > > for ii=1:8
> > > data{ii}=xlsread('raw data.xls',sheets{ii})
> > > end
> > >
> > > /per
> >
> > Actually, looked at the data a little more, and while that does bring in all the data, there is are no tags on the data. Is there a way to bring the data in as individual variables?
>
> The full syntax reads:
>
> [num, txt, raw] = xlsread(filename, ...)
>
> What do you mean by "tags"?
>
> XLSREAD splits the contents of the sheet. Numerical data goes into num and text into txt. Be aware that num(1,1) might not refer to the same cell as txt(1,1). raw holds both numerical and text data. I guess you will find the "tags" in txt and raw.
>
> No, I don't know how to avoid the default sheets, sheet1, ... . However, with the Ms COM-ActiveX-??-object you can do "everything". It might be worth searching the File Exchange.
>
> / per
>
>


By tags I mean the name of the worksheet, in this case the filename saved to the worksheet.

Subject: xlsread

From: per isakson

Date: 19 Jan, 2009 21:20:18

Message: 7 of 7

"Travis" <sinusoid2@hotmail.com> wrote in message <gkt759>
....
By tags I mean the name of the worksheet, in this case the filename saved to the worksheet.

xlsinfo returns the names of the worksheets - but you know that.

/per

Tags for this Thread

Everyone's Tags:

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
xlsread Travis 13 Jan, 2009 18:15:06
excel Travis 13 Jan, 2009 18:15:06
spreadsheets Travis 13 Jan, 2009 18:15:06
rssFeed for this Thread

Contact us at files@mathworks.com