Matlab:存储大量数据

时间:2015-07-08 21:21:38

标签: arrays excel matlab file csv

我的csv文件看起来像这样

'have', 1436271616097.0, 33.0, 'noChange', 1436271538982.0
'four', 1436271616130.0, 466.0, 'noChange', 1436271538982.0
'have', 1436271616596.0, 467.0, 'noChange', 1436271538982.0
'four', 1436271617063.0, 100.0, 'noChange', 1436271538982.0

我尝试使用[num, txt, raw] = csvread('test.csv') 它显示错误说输出参数太多。

我尝试将我的csv文件转换为.xlsx,但随后将数字更改为此,

have    1.44E+12    33   noChange   1.44E+12
four    1.44E+12    466  noChange   1.44E+12
have    1.44E+12    467  noChange   1.44E+12
four    1.44E+12    100  noChange   1.44E+12
minutes 1.44E+12    666  noChange   1.44E+12

然后我使用了[num, txt, raw] = xlsread('test.xls') 但问题是如果我显示eyeT = vpa(eyeT(:,1))它显示相同的浮点值。我怎样才能使用textscan?

1 个答案:

答案 0 :(得分:1)

这是使用textscan作为上述csv文件的简短示例。这为每列提供了一个单元格数组。

% reading the data
file = fopen('file.csv');
F = textscan(file,'%s %f %f %s %f','Delimiter',',');

format long    % to show all the digits of the large number
celldisp(F)    % display the values of all cells

结果如下:

F{1}{1} =
'have'
F{1}{2} =
'four'
F{1}{3} =
'have'
F{1}{4} =
'four'
F{2} =
   1.0e+12 *
   1.436271616097000
   1.436271616130000
   1.436271616596000
   1.436271617063000
F{3} =
    33
   466
   467
   100
F{4}{1} =
'noChange'
F{4}{2} =
'noChange'
F{4}{3} =
'noChange'
F{4}{4} =
'noChange'
F{5} =
   1.0e+12 *
   1.436271538982000
   1.436271538982000
   1.436271538982000
   1.436271538982000