MATLAB: Problem in importing textfiles

data importdecimal commadecimal pointdecimal radixmatrixradix pointtext file

Hello,
I would like to import a textfile with matlab. The textfile consist of decimal numbers. It looks like:
X Y Z
0,1 0,2 0,3
0,4 0,5 0,6
0,7 0,8 0,9
I use the following code to import the data:
filename = 'Textfile-test.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
My problem is that the numbers are not imported by matlab. Do you have any idea how to solve this problem.
Thank you in advance

Best Answer

MATLAB only recognizes the period character as the decimal radix, so you will need to change that comma character before converting to numeric. To achieve this when reading the file with MATLAB, you could do something like this:
fid = fopen('temp.txt');
C = textscan(fid, '%s%s%s');
fclose(fid);
C = [C{:}];
hdr = C(1,:);
dat = regexprep(C(2:end,:),',','.');
dat = cellfun(@(s)sscanf(s,'%f'),dat);