Loading text file with header and using Textscan yeilding empty array

조회 수: 3 (최근 30일)
Chandan Dey
Chandan Dey 2020년 3월 19일
댓글: Chandan Dey 2020년 3월 21일
I am unable to load data in txt file with header information using fopen and textscan. Below is the header type and the numeric data follows.
/datum 10000.00
/0057841A
/60Hz AC filter
/13.5V
/tune initialize N auto-tune Y 048.8uT
/time nT sq
000002.0 48812.27 99
000007.0 48812.26 99
000012.0 48812.27 99
000017.0 48812.31 99
000022.0 48812.26 99
I have tried using the following code but the data array has empty value irrespective of the last step. I know there's a silly error in my code. Would like to request for correction. Thanks in advance. One more question: How can I load this txt file in matlab and simply replace the '/' of header information with '%'?
fid=fopen('file.txt','r');
data=textscan(fid,'%f%f%d','HeaderLines',6);
data=cell2mat(data);

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2020년 3월 19일
Your code works fine, not sure what is the problem.
Another way is to use importdata()
out=importdata('file.txt',' ',6)
str=strrep(out.textdata(:,1),'/','%')
  댓글 수: 1
Chandan Dey
Chandan Dey 2020년 3월 21일
importdata works fine but I wanted to use the fid method. Anyways, thank you.

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

카테고리

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