How to read some specific columns from xls file with matlab

61 ビュー (過去 30 日間)
Sabrina
Sabrina 2014 年 8 月 20 日
編集済み: Sabrina 2014 年 8 月 21 日
Hello,
i'm a new user of Matlab, and i would like to know how I can choose some specific columns
For example :
B C D E
a480.1 *c450* a488 *c555*
0.5 *0.8* 0.6 *0.84*
In this case i need to read C and E.
Thank you very much
H

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 20 日
data1=xlsread('file.xlsx','C:C');
data2=xlsread('file.xlsx','E:E');
data=[data1 data2]
  1 件のコメント
Sabrina
Sabrina 2014 年 8 月 21 日
Thanks Azzi, the problem is that I ve tried this method, but it took me a lot of time, that's why I'm trying to find the simple way

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2014 年 8 月 20 日
Unless there are a very large number of columns being ignored, far simpler to just read the whole spreadsheet then eliminate the columns not needed.
In this case since there's a mess of alphanumeric and numeric data, probably best is to use the RAW cell array result directly --
[~,~,dat]=xlsread('filename.xls');
dat=[dat(:,2) dat(:,4)];
  4 件のコメント
dpb
dpb 2014 年 8 月 21 日
If the columns you want are close to each other you can try to minimize the extra input by defining the block to enclose the columns you wish as first and last. I'd guess w/o trying it that the extra overhead in xlsread of handling the block will be as much or more as that in reading the full file.
Certainly the option of reading the file multiple times is surely going to be the slowest option I'd think without question.
So, "it depends" I suspect, altho I still think the fastest will likely be the read it all into memory, then operate on that.
Sabrina
Sabrina 2014 年 8 月 21 日
編集済み: Sabrina 2014 年 8 月 21 日
waw it worked, thank you so much :-) dpb !! of course I have to put all the colmuns I need but it's more easy and helpful than my first script, which is too long
thanks a lot
H

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeActiveX についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by