Reading certain rows from txt file.
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jesus Escareno
le 26 Nov 2019
Commenté : Jesus Escareno
le 2 Déc 2019
Im trying to read certain ranges from a txt file. I essentially need to show two plots but my data is broken up by some text in the middle. Is it possible to read the data and skip just the txt part.
0 commentaires
Réponse acceptée
Kaashyap Pappu
le 29 Nov 2019
The following code will read the data as you require:
% Setup the Import Options
opts = delimitedTextImportOptions("NumVariables", 2);
opts.DataLines = [2, Inf];
opts.Delimiter = ["\t", " "];
opts.VariableNames = ["title", "MachNumber"];
opts.VariableTypes = ["double", "double"];
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts.ConsecutiveDelimitersRule = "join";
% avoid rows with text settings
opts.ImportErrorRule = "omitrow";
opts.MissingRule = "omitrow";
% Import the data
requiredTable = readtable("CASE1_MACH.txt", opts);
Hope this helps!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!