필터 지우기
필터 지우기

Problem while using textscan

조회 수: 1 (최근 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 CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by