extracting data from a .rec file

조회 수: 26 (최근 30일)
Esmond
Esmond 2012년 11월 22일
I want to write some code that will open a simple .rec file, (which I'm able to open manually by just clicking on it in Matlab), then read along line by line, extracting two bits of data from each line that I can identify as being a certain number of spaces past a set character, and doing so until the first line in which another character appears.
I've tried using fopen, fscanf, fget1 and fprintf, but whenever I try and use fopen it just returns a 1*1 double.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 11월 22일
fopen() is intended to return a 1*1 double. The value it returns is the file identifier that is needed for further file operations. fopen() itself does not read any data.

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

답변 (1개)

Esmond
Esmond 2012년 11월 22일
편집: Esmond 2012년 11월 22일
Thanks Walter. That clears up why I'm getting a double for that.
This is my code for just reading and re-writing the file, it works on a plain text file, but won't work on the .rec file, despite it being openable manually from Matlab.
f=fopen('Pop-1.rec','r');
fnew=fopen('Pop-1_edit.txt','w');
lastline = 'Rank = 2';
stop=0;
while stop==0
s=fgetl(f);
fprintf(fnew,'%s\n',s);
if strcmp(s(1:length(lastline)),lastline)==1
stop=1;
end
end

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by