Prev: Problems in Simulink -> Code Compose Studio V3.3 (CCS) about toolbox C2000 when used RTDX functions
Next: Array in Array
From: Steven Lord on 15 Jun 2010 09:46 "Steph T" <stephanie.turnbull(a)strath.ac.uk> wrote in message news:hv7svo$nf5$1(a)fred.mathworks.com... > "sscnekro " <stiahni.mail(a)zoznam.sk> wrote in message > <hv7pe0$9jm$1(a)fred.mathworks.com>... >> > But is there a way of using xlsread more efficiently, rather than >> > having to use it 280 times? >> >> That's a bit up to you. In what way are your data stored in the .xls >> file? E.g. if all the sheets are arranged the same way (so that ML can >> start reading data from the same range or cell), it simplifies a lot. >> Have you got ready 280 variable names, or do you still need to create >> them? What sort of variable do you prefer to create, matrix, cell array, >> structure...? Help doc: xlsread(), for loop, structures, field names, ... >> + browsing the web for some keywords will get to useful hints on other >> and these sites. > > I have 280 identical sheets where I'd be extracting the whole sheet, each > called p# where # is a sequential sheet number. Ideally I'd want to read, > for example, sheet p1 into variable p1, sheet p2 into variable p3, etc. Do NOT do this; see Q4.6 in the newsgroup FAQ for some of the reasons why this is discouraged and the alternatives you should use instead. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Leslie McBrayer on 15 Jun 2010 09:49 >> I have 280 identical sheets where I'd be extracting the whole sheet, each >> called p# where # is a sequential sheet number. Ideally I'd want to read, >> for example, sheet p1 into variable p1, sheet p2 into variable p3, etc. > > Do NOT do this; see Q4.6 in the newsgroup FAQ for some of the reasons why > this is discouraged and the alternatives you should use instead. > Perhaps consider the importdata function, which reads all the sheets into a structure array. For example: alldata = importdata('myfile.xls'); The exact structure of "alldata" depends on whether your sheets have any text in them (such as column or row headers). If there is any text in the sheets, use this sort of syntax to view the numeric data from the first sheet: alldata.data.p1 But if all of the sheets only have numeric data, use this syntax: alldata.p1
From: sscnekro on 15 Jun 2010 10:05 > sheet p1 into variable p1, sheet p2 into variable p3, etc. > each variable as separate matrices. > Re: Steven Lord You mentioned that you are new to Matlab so there might be some aversion of going into things you don't know. On the other hand, your problem may not be that "basic" as your experience. If I were you I would try to describe here what you need to to and try to ask CSSM-ers about the most appropriate type of variable and way of arranging data in it. What do you plan to do with your variables in Matlab? Computations, plotting? You may create a 3D matrix with 280 pages, a 3D cell array, or structure. PS You may check out the functions you plan to use first and see how inconvenient it might be to use names such as p1, p2, etc, in these functions.
From: Steph T on 18 Jun 2010 06:17
Thank you all for your help. I managed to write a loop that would read each sheet and save as a separate variable, however with the advice on here and from collegues I decided to use a structure instead, which made the solution a little more elegant, but not significantly faster... Thanks again, Steph |