dlmread reading file incorrectly

조회 수: 9 (최근 30일)
Shahar Idan
Shahar Idan 2016년 3월 9일
댓글: Shahar Idan 2016년 3월 9일
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.

채택된 답변

Stephen23
Stephen23 2016년 3월 9일
편집: Stephen23 2016년 3월 9일
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
  댓글 수: 1
Shahar Idan
Shahar Idan 2016년 3월 9일
thank you so much! saved my hours for my research! i noticed that the function dlmread was changed between matlab 2014 and 2016 an apparently my university updated to the newest version causing the function to read incorrectly '\t' or TAB. again, thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by