problem with xlsread:Bizarre results
古いコメントを表示
Dear all,
I have an excel file that contains 3 sheets
when I look at each of these sheets inside the excel file they all have the same number of rows( 245) but when I use the command
[num1 ,txt1 ,raw1 ] = xlsread(xlfilename,1);
[num2 ,txt2 ,raw2 ] = xlsread(xlfilename,2);
[num3 ,txt3 ,raw3 ] = xlsread(xlfilename,3);
I get that raw1 has 266 rows
raw2 has 267 rows
raw3 has 279 rows
I also noticed that inside the workspace matlab adds arbitrarily different number of rows of NaN at the end of the raw1 raw2 raw3
Bear also in mind that “raw1” “raw2” “raw3” contains string numbers and empty cells
Unfortunately it is not convenient for my purposes to use “num1““num1“ “num1“
Thank you
採用された回答
その他の回答 (1 件)
F.
2012 年 7 月 4 日
Hello,
I think the problem is with Excel.
I think you should have at a moment more than 245 lines, and you should have deleted them. You don't see these old lines in excel, but the application remains it. When you are using xlsread, you import these empty lines. You can see this with raw datas.
When you want import data from excel, 2 solutions:
- First, in excel you select all lines ( and after all columns ) after your data and you remove them (not only delete)
- !the other one, with raw data you can define lines and columns with no data or NaN data, and you delete them :
[ N, T, R ] = xlsread( ‘toto.xls’ );
Tmp = cellfun( @isnan, R, ‘UniformOuput’, true);
R( all( Tmp,1), : ) = [] ;
R( : , all( Tmp,2) ) = [] ;
Or something like this (I’m sorry but I don’t have Matlab on my Pc today) (it’s the same thing with “empty” )
8 件のコメント
Sabbas
2012 年 7 月 4 日
F.
2012 年 7 月 4 日
I don't undersand your comment. If you want just erase rows from your raw data :
Tmp = cellfun( @isnan, R, 'UniformOutput', true)
R(all(Tmp,2),: )=[]
but if you have some rows with NaN in your data and you can use :
Tmp = cellfun( @isnan, R, 'UniformOutput', true)
Tmp = find( ~all(Tmp,2),1, 'last')
R((Tmp+1):end,: )=[]
otherwise, I'm sorry, I didn't undersand your problem because, for me, it's just a problem with NaN rows at the end of your data ...
Sabbas
2012 年 7 月 4 日
F.
2012 年 7 月 5 日
The reason is some cells contain string. Try this :
Tmp = cellfun( @(C) all(isnan(C)), R, 'UniformOutput', true)
Mark Whirdy
2012 年 7 月 5 日
or
Tmp = cellfun( @isnan, R, 'UniformOutput', false)
as per error?
Need to start looking at the data and removing unncessary rows with cellfun(@isnumeric, cellfun(@isnan etc etc. Just experiment
F.
2012 年 7 月 5 日
If you use this command, you will have a cell array for "Tmp", and we need an array.
Sabbas
2012 年 7 月 5 日
Mark Whirdy
2012 年 7 月 9 日
cell2mat
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!