Handling excel file
1 view (last 30 days)
Show older comments
I need to read an excel formated data into Matlab. This data file contains 33757x50 cells, and there are several nonconsecutive rows and columns that hold characters. What I need finally is a sub-sheet, say, the 3,7,10,11,14,19,25,27,31,...,232,300th rows from the original sheet of the excel file. the excel read command >>xlsread(filename,sheet,range) does not have such kind of function since the option 'range' should be consecutive, e.g., B2:F50. Any good suggestions are appreciated!
Richard
1 Comment
Walter Roberson
on 26 Feb 2011
It sounds to me as if something like a mysql database would be more appropriate for your needs.
Answers (3)
Matt Tearle
on 24 Feb 2011
Why not import everything, then strip out any blank rows?
[~,~,x] = xlsread('foo.xls');
x(all(cellfun(@isempty,x),2),:) = [];
4 Comments
Matt Tearle
on 27 Feb 2011
See Chris Hinkle's comments. x in my example is a cell array of everything, so the indexing I showed works just fine, as long as you know what idx is. You could also investigate using the is* functions and/or cellfun. E.g. c(~cellfun(@isnumeric,c(:,1)),:) = []; would remove any rows where the first column is not numeric.
Oleg Komarov
on 26 Feb 2011
Other than importing the entire excel as Matt suggest (which I would go for unless the number of rows selected is just a tiny part of a huge excel), it would require to go to the low level using actxserver.
Then you can select specific ranges as this tutorial shows: How to select cells/ranges by using Visual Basic procedures in Excel
Oleg
0 Comments
chris hinkle
on 27 Feb 2011
Some tips
1. Xlsread allows you to bring in raw numeric and text [Numeric text raw] = xlsread() so everything will be parsed for you
So once you have this you will see numeric is an array of doubles and text is a cell array of strings while raw is a cell array of mixed types
2. Depending on your selection criteria you need to use the find command with criteria for numbers or if for example you wanted to get rid of rows with empty fields get the indices by using strcmp, this DOES work with cell array of strings. Hope this helps
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!