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 Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by