【问题标题】:Matlab: loading every n-th column of a csv with varying formats in row using textscanMatlab:使用 textscan 在行中加载具有不同格式的 csv 的每个第 n 列
【发布时间】:2015-08-03 19:07:42
【问题描述】:

我正在尝试加载带有分号 (;) 分隔符的 csv 文件。

例子:

150501;190722;ms_since_start=;30001276;temp=;31.97;IT=;147753;spec num=;1000;(here i have 512 floating number repetitions and ';;' to indicate the end of line) 

此模式重复 1000 行。

我一直在尝试使用 textscan,但只能使用以下代码获取空单元格

formatSpec = ['%s%s%*s%*s%*s%*s%*s%*s%*s%*s%*s' repmat('%f', [1,512]) '%*[^;;]']
M = textscan(dirtmp, formatSpec, 'Delimiter', ';')

目标是获取前 2 列,跳过 9 列,获取剩余的 512 列,然后对 1000 行重复此操作。

非常感谢任何帮助

【问题讨论】:

    标签: matlab


    【解决方案1】:

    看看这个问题的答案1。我认为您实际上不能跳过该列,但是一旦获得输出,您就可以说:

    x = read_mixed_csv('example.csv',';');
    y = x{:, [1,2, 11:size(x, 2)]};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多