MATLAB Answers

Reading certain rows from txt file.

9 views (last 30 days)
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 Comments

Sign in to comment.

Accepted Answer

Kaashyap Pappu
Kaashyap Pappu on 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);
Additionally, you can look into the Import Tool to easily load data from files into workspace.
Hope this helps!

  1 Comment

Jesus Escareno
Jesus Escareno on 2 Dec 2019
Great this is what I needed.
Thank You

Sign in to comment.

More Answers (0)


Translated by