dlmread reading file incorrectly
조회 수: 9 (최근 30일)
이전 댓글 표시
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
채택된 답변
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.
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!