将复杂的excel或csv文件读入matlab [英] read complicated excel or csv file into matlab

查看:203
本文介绍了将复杂的excel或csv文件读入matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个excel文件,它是一个混合的文本文件和数值。
例如,文件看起来像这样,

  25 file1 
26 file2

这里25是第一个单元格中的数值(行1,列1)。 file1表示第二个单元格中的内容(row1,column2)。它可以是由多个段落组成的短文本文件。



我想将这个excel文件加载到matlab中,并将其存储为2 * 2矩阵。每个矩阵条目对应于矩阵单元。



我试过 xlsread ,但没有起作用。我也尝试过 textscan ,但它似乎能够处理一个单元格只有一个字符串的场景。这里,一些单元格的内容本身就是文本文件。

解决方案

如果您正在使用 XLSREAD ,您可以使用第三个输出参数来检索文本和数字数据(例如:

 >> [〜,〜,raw] = xlsread('Book1.xls')
raw =
[25]'你好世界'
[26] [1x38 char]

>> raw {2,2}
ans =
这是一个例子
的多行
文本

请注意,XLSREAD仅限于MS Excel打开/读取文件的功能,因此一些特别大的文件(在我的体验1百万行中)将只能部分阅读。 p>

I have an excel file, which is a mix of text file and numerical values. For instance, the file look like this,

25  file1
26  file2

Here the 25 is an numerical value in the first cell (row 1, column1). "file1" represents the content in the second cell(row1, column2). It can be short text file composed of multiple paragraphs.

I want to load this excel file into matlab, and store it into a 2*2 matrix. Each matrix entry corresponds to a matrix cell.

I tried xlsread, but it did not work. I also tried textscan, but it seems to be able to handle the scenario where a cell has a string only. Here, the contents of some cells are text files itself.

解决方案

If you are reading an Excel file using XLSREAD, you can use the third output argument to retrieve the both the textual and numeric data (unprocessed).

Example:

>> [~,~,raw] = xlsread('Book1.xls')
raw = 
    [25]    'hello world.'
    [26]       [1x38 char]

>> raw{2,2}
ans =
this is an example
of multi-line
text

Note that XLSREAD is limited to the capabilities of MS Excel to open/read files, so some especially large files (in my experience 1 million+ rows) will get only partially read.

这篇关于将复杂的excel或csv文件读入matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆