【问题标题】:Extracting the numbers in the 5th column only from a text file仅从文本文件中提取第 5 列中的数字
【发布时间】:2014-10-21 06:51:50
【问题描述】:

我有一个 .txt 文件,它有 82332 行和 5 列。我只想将第 5 列中的数字提取到向量中。这在 Matlab 中可能吗?

文本文件如下所示。
1.0000000e+00 6.0205125e+01 -1.1923175e+02 3.5341908e+02 3.7197225e-01

任何提示或提示表示赞赏。

【问题讨论】:

    标签: matlab


    【解决方案1】:

    使用textscan,您可以指定忽略格式规范中带有* 修饰符的字段(列)。

    fid = fopen('test_data.txt','r');
    C = textscan(fid,'%*f%*f%*f%*f%f');
    fclose(fid)
    

    您的向量是C{1}。注意:如果有要忽略的尾随列,您可以使用 %*[^\n] 跳过该行的其余部分。


    您也可以将dlmreadrange 输入参数一起使用如果您知道文件中的行数:

    col = 5; numRows = 24;
    dlmread('test_data.txt','',[1 col numRows col] - 1)
    

    【讨论】:

    • 不知道*。感谢您的洞察力!
    猜你喜欢
    • 2016-10-27
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多