xlsread for many distinct columns that aren't side-by-side in the SS

1 回表示 (過去 30 日間)
John
John 2014 年 2 月 26 日
回答済み: Nick Haddad 2014 年 10 月 3 日
Hi,
I know this is probably simple, but I'm not finding what I need when searching here.
I want to use xlsread to import many distinct columns that are not side-by-side in the spreadsheet. How can I do that? What am I missing? :)
My normal use of xlsread would be like this if I need columns A-D:
[File,Path] = uigetfile(blah, blah, blah);
File = strcat(Path,File);
DataVariable = xlsread(File,1,A:A:D:D);
How would I change this if I wanted, say, columns A and columns D-F? I've tried many different things, but have suffered death by commas, semicolons, and error messages.
Any help is appreciated.
  2 件のコメント
John
John 2014 年 2 月 26 日
Bumping this back up... :)
Jan
Jan 2014 年 2 月 26 日
編集済み: Jan 2014 年 2 月 26 日
Please, John, do not bump your question after a few hours without addibng new information. The voluntary helpers post answers whene ever they have them and find the time to help. Reading a question again is a waste of time then.
The posted code is not working. Did you forget the quotes around A:A:D:D? But even then this is not correct.

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

回答 (4 件)

Jan
Jan 2014 年 2 月 26 日
Import the block at first:
[File,Path] = uigetfile(blah, blah, blah);
File = fullfile(Path,File); % Smarter than STRCAT
DataVariable = xlsread(File,1,'A1:F231');
Now remove the not needed data from the output DataVariable.
This is not nice, but it works reliably.
  2 件のコメント
John
John 2014 年 2 月 27 日
I actually tried that way, but ML told me there wasn't enough storage to import that much info. It's trying to import millions of cells.
Image Analyst
Image Analyst 2014 年 2 月 27 日
Does your xlsread call specify a range? You might have to process your data in smaller chunks.

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


Image Analyst
Image Analyst 2014 年 2 月 26 日
Have you tried readtable() - it's new in R2013b and reads the Excel workbook into a table which is a lot more convenient than that mess of cell arrays xlsread() spits out. I've kissed xlsread() goodbye. You will too after you use readtable().
  4 件のコメント
John
John 2014 年 2 月 27 日
I can try that, but I'm fearful I'll run into what I ran into in the above comment under Jan Simon's answer (that ML will tell me there's not enough storage to complete it).
John
John 2014 年 2 月 27 日
I have R2013a, so no readtable for me :(. Looks like it would have worked better too.

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


Sean de Wolski
Sean de Wolski 2014 年 2 月 27 日
  3 件のコメント
Sean de Wolski
Sean de Wolski 2014 年 2 月 27 日
If you contact our customer service department they can straighten that out.
Otherwise just search for "Excel Automation" in the MATLAB doc; it should be the first result.
John
John 2014 年 2 月 27 日
So, Excel Automation is working nicely. However, there's an issue I'm running into.
It requires that you define which sheet you want to use by way of using the sheet name. The sheet name, in my case, is different for every excel file, but does contain part of the file name. The file name is so long, it only allows part of the file name to be placed in the sheet name. My file names I'm using contain many bits of info separated by underscores.
XXX_###_ABC_###_YYY_blah_blah_blah
But, in the sheet name, it cuts off the filename at the same underscore each time.
Can I tell ML to take the filename up until, say, the fifth underscore, and use that as the sheet name?
Or is there a generic way to tell it to define the sheet name as whatever the sheetname actually is? Something similar to the Activesheet command in VBA?

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


Nick Haddad
Nick Haddad 2014 年 10 月 3 日
This issue is a known bug in MATLAB and has been addressed in the following bug report:
The bug report has a workaround which you can install for MATLAB R2013a through R2014b.

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by