MATLAB textscan标题行 [英] MATLAB textscan headerlines

查看:77
本文介绍了MATLAB textscan标题行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将 headerslines textscan 一起使用以跳过文本文件的第一行时,我所有的数据单元格都存储为空.

When I try to use headerlines with textscan to skip the first line of the text file, all of my data cells are stored as empty.

fid = fopen('RYGB.txt');
A = textscan(fid, '%s %s %s %f', 'HeaderLines', '1'); 
fclose(fid);

此代码给出

1x4 Cell
[] [] [] []

如果没有 headerslines 部分,并且文本文件中无需跳过第一行,则可以毫无问题地读取数据.它会创建一个 1x4单元格,其中的数据单元格包含列中文本文件中的所有信息.

Without the headerlines part and without a first line that needs to be skipped in the text file, the data is read in with no problem. It creates a 1x4 cell with data cells containing all of the information from the text file in columns.

如何跳过文本文件的第一行并正常读取数据?

What can I do to to skip the first line of the text file and read my data in normally?

谢谢

推荐答案

我认为您的问题是您为指定了 string 而不是 integer 值> HeaderLines .字符'1'被解释为其ASCII值0x31(十进制49),因此跳过了前49行.您的文件可能包含49行或更少的行,因此所有内容最终都将被丢弃.这就是为什么您要清空单元格的原因.

I think your problem is that you have specified a string instead of an integer value for HeaderLines. The character '1' is interpreted as its ASCII value, 0x31 (49 decimal), so the first 49 lines are skipped. Your file probably contains 49 lines or less, so everything ends up being discarded. This is why you're getting empty cells.

解决方案是将'1'替换为 1 (删除引号),如下所示:

The solution is to replace '1' with 1 (i.e. remove the quotes), like so:

A = textscan(fid, '%s %s %s %f', 'HeaderLines', 1);

这应该可以解决问题.

这篇关于MATLAB textscan标题行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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