필터 지우기
필터 지우기

Reading data from a text file

조회 수: 18 (최근 30일)
nl2605
nl2605 2013년 7월 25일
Hallo
I usually used load function to read text files. However, this time my text file has the first column as p1 p2 p3 and so on. How can I not read this column and load only the next available columns. I used fopen, fscanf and fclose but it gives an empty array as output.
Thanks in advance.

채택된 답변

Narges M
Narges M 2013년 7월 25일
편집: Narges M 2013년 7월 25일
use this example:
cfg = fopen('myfile.txt');
line = fgetl(cfg); %this line reads the first line, you can discard it right away
while( ~feof(cfg) )
line = fgetl(cfg);
% read your data here, using textscan for example
end
or use this:
f = fopen('myfile.txt');
E = textscan(f,'%s %f %f %f','delimiter', ' ', 'collectoutput',false,'BufSize',10000);
end
  댓글 수: 11
Narges M
Narges M 2013년 7월 25일
편집: Narges M 2013년 7월 25일
that's done automatically. refer to "help importdata"
nl2605
nl2605 2013년 7월 25일
Thanks! got it!

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

추가 답변 (1개)

kjetil87
kjetil87 2013년 7월 25일
편집: kjetil87 2013년 7월 25일
perhaps you are using fscanf(fid,'%d') ?
Try reading it as characters:
fid=fopen('text.txt');
DATA=fscanf(fid,'%c');
fclose(fid);
  댓글 수: 4
Narges M
Narges M 2013년 7월 25일
E = textscan(f,'%s %f %f %f','delimiter', ' ', 'collectoutput',false,'BufSize',10000);
nl2605
nl2605 2013년 7월 25일
tried this way too. But it gives E=0.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by