dlmread reading file incorrectly
8 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Stephen23
on 9 Mar 2016
Edited: Stephen23
on 9 Mar 2016
The data you have shown does not use tab as the delimiter, but uses four space characters.
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
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!