Reading certain rows from txt file.

조회 수: 27 (최근 30일)
Jesus Escareno
Jesus Escareno 2019년 11월 26일
댓글: Jesus Escareno 2019년 12월 2일
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.

채택된 답변

Kaashyap Pappu
Kaashyap Pappu 2019년 11월 29일
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
Jesus Escareno
Jesus Escareno 2019년 12월 2일
Great this is what I needed.
Thank You

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by