Azzera filtri
Azzera filtri

Problem while using textscan

1 visualizzazione (ultimi 30 giorni)
Shelender Kumar
Shelender Kumar il 26 Ott 2018
Commentato: Star Strider il 31 Ott 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

Risposta accettata

Star Strider
Star Strider il 26 Ott 2018
Modificato: Star Strider il 26 Ott 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 Commenti
Shelender Kumar
Shelender Kumar il 31 Ott 2018
Thanks a lot it helps
Star Strider
Star Strider il 31 Ott 2018
As always, my pleasure.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by