Assigning two seperate EXCEL columns to two arrays in one go

7 ビュー (過去 30 日間)
Jason
Jason 2015 年 4 月 13 日
コメント済み: Philip Caplan 2015 年 4 月 16 日
I have a very large Excel file (848,000 lines), and I want to read 2 seperate columns and assign to two different arrays. I am able to assign the first column A to an array "text1".
ct1=sprintf('A%d:A%d',idx1+1,idx1+count)
[ndata, text1]=xlsread(file,ct1);
Because it takes about 3 minutes to do this, I dont want to sequentially do the same to read Column J of the same spreadsheet and assign to text2. Is it possible to read two discrete columns and assign to two separate arrays in one go? Thanks
  1 件のコメント
Guillaume
Guillaume 2015 年 4 月 16 日
Is the file an excel file as stated above, or a text file as stated in your comment to Philip answer?

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

回答 (1 件)

Philip Caplan
Philip Caplan 2015 年 4 月 15 日
It is only possible to import a rectangular range when using either "xlsread", "csvread" or "readtable", therefore, your columns will need to be side-by-side in order to import them into MATLAB with one call to the aforementioned functions. For example:
>> [ndata,text1] = xlsread(file,'B3:D7');
will read your file from rows 3-7 and columns B to D. You can then extract the data from the returned array but the key is that the columns you want to read need to be adjacent.
  2 件のコメント
Jason
Jason 2015 年 4 月 16 日
Thanks for clarifying. My file is although saved as a CSV is actually tab delimited. Are there any alternative ways to achieve what I want not using xlsread? Jason
Philip Caplan
Philip Caplan 2015 年 4 月 16 日
In that case I would suggest using "textscan" and following the example at:

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by