Loading text file with header and using Textscan yeilding empty array
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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),'/','%')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!