Effacer les filtres
Effacer les filtres

Problem while using textscan

1 vue (au cours des 30 derniers jours)
Shelender Kumar
Shelender Kumar le 26 Oct 2018
Commenté : Star Strider le 31 Oct 2018
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

Réponse acceptée

Star Strider
Star Strider le 26 Oct 2018
Modifié(e) : Star Strider le 26 Oct 2018
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 commentaires
Shelender Kumar
Shelender Kumar le 31 Oct 2018
Thanks a lot it helps
Star Strider
Star Strider le 31 Oct 2018
As always, my pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by