Alvin Nunez
Alvin Nunez

Reputation: 247

Reading text files by line and storing character values in a cell string? (MATLAB)

I have a function that I use for single strings. However, I want to extend this to many text files.

My text files are of the form of:

first line of garbage

continuous text with no spaces

continuous text with no spaces

continuous text with no spaces

continuous text with no spaces

There are no blank spaces between the lines (Stack Overflow requires a double space for a new line). I would like to read each line of continuous text and store it in the element of a cell of strings. How could I do this?

EDIT: I know I would have to do something along the lines of:

file1 = fopen(link','rb');
while file ~EOF
grab every text value by line, call it data
file1 = fopen(file1, data)
store in cell array

Upvotes: 2

Views: 380

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

You can use importdata:

C = importdata('file.txt'); %// import each line into a cell
C = C(2:end); %// remove first cell (header)

Upvotes: 1

Related Questions