0

I'm using Matlab 2012a to append a <1x19 cell> to a CSV file using dlmwrite. The cell array includes 17 numbers and 2 blanks. The result: 17 values written to the target csv file, but the two blanks missing. I am using the codes below:

    Output=num2cell([var1,var2,var3....var19]);
    Output(cellfun(@isnan,Output)) = {[]};
    dlmwrite('Target.csv',Output_m,'-append');

When I run the codes in command window I can see the blanks appear in the Output:

    Output = 

    Columns 1 through 10

    [19]    [2]    [137.5994]    [0]    []    [501.3610]    [38.4230]    [0]    [0]    [4.9160]

    Columns 11 through 19

    [4.9160]    [38.4230]    [0]    [38.4230]    [501.6580]    []    [-1.2590]    [0]    [0]

But when appended to the csv file, the blanks disappear.

Thanks.

4

1 回答 1

1

这在文档中列出:

dlmwrite(filename,M) 将数组 M 中的数值数据写入 ASCII 格式文件 filename,使用默认分隔符 (,) 分隔数组元素。如果文件 filename 已经存在,dlmwrite 将覆盖该文件。

非数字数据被忽略,这就是数据丢失的原因。

解决问题的一种方法是写一个数字-Inf,然后使用后处理器删除这些元素

于 2013-10-10T03:00:18.020 回答