将制表符分隔的txt文件读入matlab [英] read a tab delimited txt file into matlab

查看:186
本文介绍了将制表符分隔的txt文件读入matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MatLab中读取制表符分隔的txt文件. 该文件具有由数字,文本,日期,日期时间以及您能想到的所有内容组成的列.有些列中的句子很长,包括逗号和其他所有内容.

I am trying to read a tab delimited txt file in MatLab. The file has columns composed of numbers, text, dates, datetimes, everything you can think of. Some of the columns have very long sentences in them, with commas and everything.

它超过了excel的行数限制(我大约有150万行),因此我无法将其转换为CSV或XLSX文件.

it exceeds the row limit of excel (i have about 1.5 million rows) so I can not convert it to a CSV or an XLSX file.

我尝试了以下操作:

tableDataEDM = tdfread(pathDataEDM,'\t');

我回来了需要统计和机器学习工具箱" 我没有它

I get back 'need the statistics and machine learning toolbox' I dont have it

tableDataEDM = dlmread(pathDataEDM,'\t');

文件和格式字符向量之间不匹配. 我回到无法从文件中读取数字"字段"

Mismatch between file and format character vector. I get back 'Trouble reading 'Numeric' field from file'

这是因为文件包含文本,数字和日期以及其他所有内容. dlmread喜欢我猜的数字数据

this is because the file has text and numbers and dates and everything else. dlmread likes numeric data i guess

       tableDataEDM = readtable(pathDataEDM,'Delimiter','\t','ReadVariableNames',true);

I get back:
    Error using readtable (line 197)
    Reading failed at line 6. All lines of a text file must have the same number of delimiters. Line 6 has 10
    delimiters, while preceding lines have 32.

    Note: readtable detected the following parameters:
    'HeaderLines', 0, 'Format', '%q%q%q%q%D%D%D%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%D%D%q%q%q%q%q%q%q%q%q'

    Error in Edm_FinderComp_CrossOver (line 33)
    tableDataEDM = readtable(pathDataEDM,'Delimiter','\t','ReadVariableNames',false);

我不确定为什么会这样说.我可以很容易地将此​​数据导入python.我缺少尝试将其放入Matlab的东西吗?

I am not sure why it says this though. I can import this data into python very easily. Is there something I am missing to try and get this into matlab?

对导入选项卡分隔的txt文件的任何帮助表示赞赏.我没有尝试过文本扫描,因为它看起来很痛苦.

any help on import tab delimited txt files is appreciated. I have not tried text scan because it looks painful.

推荐答案

您可以使用

You can use textscan. This will put each column in a separate cell in tableDataEDM. Assuming that for each row, you have an int \t int \t string:

tableDataEDM = textscan(fopen(pathDataEDM),'%d %d %s')

最后一个参数'%d %d %s'您应该更改以匹配您的格式.

The last argument, '%d %d %s' you should change to match your formatting.

这篇关于将制表符分隔的txt文件读入matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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