MATLAB: Dlmread reading file incorrectly

dlmread reading

Hello,
i wrote a code using the following lines:
clc
clear all
load('radius.mat')
fidEK = fopen('PerEk.dat','r');
filename = 'PerEk.dat';
PerEK = dlmread(filename,' ',2,0); %reading the PerEK.dat file
the file that i read is for example:
VARIABLES = "X","Y","PerEk"
ZONE I= 501, J= 501 DATAPACKING=POINT
0.99800E-03 0.99800E-03 0.61593E-11
0.99800E-03 0.29940E-02 0.98748E-10
0.99800E-03 0.49900E-02 0.45617E-09
0.99800E-03 0.69860E-02 0.11994E-08
what i used to receive was as following:
0.99800E-03 0.99800E-03 0.61593E-11
0.99800E-03 0.29940E-02 0.98748E-10
0.99800E-03 0.49900E-02 0.45617E-09
0.99800E-03 0.69860E-02 0.11994E-08
and now for some reason i'm getting one column. can anyone help? i tried changing
PerEK = dlmread(filename,' ',2,0);
into
PerEK = dlmread(filename,'\t',2,0);
didn't work.

Best Answer

The data you have shown does not use tab as the delimiter, but uses four space characters.
You could use textscan, which has an option to merge repeated delimiters:
opts = {'HeaderLines',2, 'MultipleDelimsAsOne',true};
fid = fopen('temp.txt','rt');
M = cell2mat(textscan(fid,'%f%f%f',opts{:}));
fclose(fid);
imports this:
>> M
M =
9.9800e-004 9.9800e-004 6.1593e-012
9.9800e-004 2.9940e-003 9.8748e-011
9.9800e-004 4.9900e-003 4.5617e-010
9.9800e-004 6.9860e-003 1.1994e-009