Loading text file with header and using Textscan yeilding empty array
3 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Fangjun Jiang
on 19 Mar 2020
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),'/','%')
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!