在Matlab中使用fget从csv文件导入数据后生成矩阵 [英] Generating a matrix after importing data from csv file with fgets in matlab

查看:319
本文介绍了在Matlab中使用fget从csv文件导入数据后生成矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从csv(文本)文件中读取数据后,我需要生成数据矩阵(用于复杂分析)(30x900). 我可以使用fgets将数据读取到matlab中,不幸的是,由于数据具有标头,因此无法使用load. 这些文件如下所示:

I need to generate a matrix (30x900) of data (for complex analysis) after reading said data from a csv (text) file. I can read the data in to matlab using fgets, unfortunately I can't use load as the data has a header. The files look like this:

872
30
FR

872
30
FR

(下面的数据需要放入矩阵中)

(Data below here needs to be put in to matrix)

0000.0 0000.0 0000.0
0001.0 0000.0 0000.0
0002.0 0000.0 0000.0

0000.0 0000.0 0000.0
0001.0 0000.0 0000.0
0002.0 0000.0 0000.0

有可能这样做吗?

推荐答案

我建议您看看 importdata .这是一个非常易于使用的高级功能.这是第四种语法:

del = ' '; % Delimiter
nHl = 5; % Number of header lines
dat = importdata('text.txt', del, nHl)

现在dat是一个结构; dat.data包含数据,并且标头进入dat.textdata.

Now dat is a structure; dat.data contains data and header goes in dat.textdata.

这篇关于在Matlab中使用fget从csv文件导入数据后生成矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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