读取csv文件内容中的逗号,matlab

读取csv文件内容中的逗号,matlab,matlab,Matlab,我有一个内容中包含逗号的csv文件 %带圆点 15.12.2012 11:27; 0.9884753 11.12.2012 11:12; 10.670.642 11.12.2012 10:57; 114.455.145 Gdata= textscan(fid, '%s %f') 它工作得很好 %但是如何处理dot呢 15.12.2012 11:27; 0,9884753 11.12.2012 11:12; 10,670.642 11.12.2012 10:57; 11

我有一个内容中包含逗号的csv文件

%带圆点

15.12.2012 11:27;   0.9884753
11.12.2012 11:12;   10.670.642
11.12.2012 10:57;   114.455.145

Gdata= textscan(fid, '%s %f')
它工作得很好

%但是如何处理dot呢

15.12.2012 11:27;   0,9884753
11.12.2012 11:12;   10,670.642
11.12.2012 10:57;   114,455.145
我怎么读呢


不幸的是,
textscan
不尊重区域设置,因此无法通过修改当前区域设置将逗号解释为小数点。作为一种解决方法,您可以读入整行,用点替换逗号,然后使用
textscan
解析该行

line = fgetl( fid );
line = strrep( line, ',', '.' );
Gdata = textscan( line, '%s %f' );

如果行中可能包含您不想替换的逗号,您可能必须求助于
regexp
或其他比简单的
strep
更奇特的方法。

这可能会解决由于同时存在“,”和“.”而可能出现的不平衡问题

fid = fopen('data.d','r');
Gdata= textscan(fid, '%s %s','delimiter', ';' )

% // cancels '.' and sets ',' as '.'
f = @(i) str2double(regexprep(regexprep(i,'\.',''),',','\.'));

Num = cellfun(f,Gdata(2),'UniformOutput' , false);

Num{:}

         ans =

       0.9885
       10.6706
       114.4551