MATLAB: How to read a text file into a list

text file

I have a text file containing strings in each row, e.g.
ABC
DEF
PQR
I would like to end up with an object that i can index – i.e. x(1) = 'ABC', x(2) = 'DEF', x(3) = 'PQR'.

Best Answer

You can read into a cell array:
>> data = fileread('file_name');
>> x = strsplit(data);
>> x{1}
ans =
ABC
>> x{2}
ans =
DEF
>>