Problem while using textscan

2 ビュー (過去 30 日間)
Shelender Kumar
Shelender Kumar 2018 年 10 月 26 日
コメント済み: Star Strider 2018 年 10 月 31 日
My file has a string as the first row and numeric values as other rows, I can get rid of the header by using formatspec and N as given textscan help. I do not want to write %f four times while using the textscan again to read the numeric data. I have given the test code and please find the sample file. Thanks for helping
filename = 'S.txt'; fileID = fopen(filename); formatSpec = '%s'; N = 4; C_text = textscan(fileID,formatSpec,N); %% Read the numeric data in the file. C_data0 = textscan(fileID,'%f %f %f %f','CollectOutput',1); %% Here I do not want to write %f 4 times

採用された回答

Star Strider
Star Strider 2018 年 10 月 26 日
編集済み: Star Strider 2018 年 10 月 26 日
If you do not want to type the format string, just use the dlmread funciton:
S = dlmread('S.txt', '\t', 1, 0)
S =
1 1 1 1
2 2 2 2
3 2 3 3
There are many ways to read files in MATLAB.
  18 件のコメント
Shelender Kumar
Shelender Kumar 2018 年 10 月 31 日
Thanks a lot it helps
Star Strider
Star Strider 2018 年 10 月 31 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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