필터 지우기
필터 지우기

Handling excel file

조회 수: 1 (최근 30일)
Changqing Xu
Changqing Xu 2011년 2월 24일
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
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
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
Changqing Xu
Changqing Xu 2011년 2월 27일
Thanks! But this does not work since the excel sheet contains different classes of data (e.g. char and numeric), and who is char and who is numerical is not so clear. The first job we shall do, I think, is to separate the char from the numerical data and save them by different variables which obviously cannot be fulfilled by xlsread; Based upon some analysis on the numerical part, we then come to the original sheet and choose some rows to form the sub-sheet, which is our destination.
Matt Tearle
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
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

chris hinkle
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

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by