Problem while using textscan

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by