Sunday, June 29, 2008

关于Matlab读取Excel的问题

日前从Matlab读取xls文件(技术员填好给我的),总是出现如下错误信息:

Skipping 16 bytes of extended strings.
XLS File contains unrecognized string header - skipping remaining text - (942:0xfb 2589).

我看出是格式的问题,可是技术员同志也说不清他用了什么高级格式。我对Excel基本一窍不通,于是上网搜索,发现关于同样错误信息提示的问题有人问过,有英语的,中文的,日文的,不过好像没人给出直接解决办法。从零碎的信息里,我摸索出一个quick and dirty的办法如下(万一今后有人再碰到):

It looks like "xlsread" in matlab has some issues reading excel spreadsheet, not all formats work. Here I'm talking about Excel Workbook and Matlab 7. If you ever get the above error message, here's a quick and dirty solution:

Go to Excel workbook file, "save as" Text (Tab delimited), and you get a plain .txt sheet. Now open the .txt from excel, "save as" workbook. Bingo! You just got yourself a .xls file that can be read by matlab.
Note, however, if the original .xls file contains more that one sheets, you'll lose that info when saving it as .txt. What I did was to convert each sheet separately, and then combine all sheets together. It worked!

从Excel打开原.xls文件,选择另存为Text (Tab delimited)的.txt文件,然后打开该.txt文件,另存回为Excel workbook。如果原文件含多个worksheet,可以一个sheet一个sheet地转换,然后组合在一起。
总之,管用。

Amendments: 1) It's possible that Excel workbook created by Office 2008 can't be handled by matlab 7 (mac).
2) For excel workbook with multiple sheets, simply combining all "de-formatted" sheets actually won't work: the first sheet reads fine, but the rest are a mess. So I ended up dealing with each sheet separately.

2 comments:

Anonymous said...

燕子,你画图用什么软件啊?

Anonymous said...

adobe illustrator, adobe photoshop
adequate for my purpose, although I believe there are many fancy functions that I have no clue how to use with these two softwares.