How can I select a specific line in a text file base on a specific string in that line?

I am trying to extract rows from a .txt file that start with a specific string. For example in the attached .txt file, I would like to only extract the values from the lines with 'CR5' into a table. My end goal here is to be able to plot the values.
Thanks.

 Accepted Answer

Read the entire file and split by newline character (e.g. with my readfile function). Then you can parse line by line in a loop, or use functions like contains.

4 Comments

How do I convert this cell into a matrix array?
[594669146 -11.745480 -0.429790 -1.62]
What you posted is already a normal array. What is your question?
It is a string array and I would like like to convert it to a numeric array. Using str2double results in an error. The goal is to extract the last value in the row for plotting porpuses.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!