Handling excel file
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-2-26
It sounds to me as if something like a mysql database would be more appropriate for your needs.
回答(3 个)
Matt Tearle
2011-2-24
Why not import everything, then strip out any blank rows?
[~,~,x] = xlsread('foo.xls');
x(all(cellfun(@isempty,x),2),:) = [];
4 个评论
Matt Tearle
2011-2-27
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
2011-2-26
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 个评论
chris hinkle
2011-2-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!