edgarmtze
edgarmtze

Reputation: 25058

Load only a column of file MATLAB

I am interested only in a column of a file, (I can not load the file normally, the rows have different size of columns)

So

>load('file.txt');  

is not working, but I want to retrieve the first column in that file

Upvotes: 0

Views: 9357

Answers (1)

Rich C
Rich C

Reputation: 3244

Use textscan to load it and skip the other columns by using an asterick.

fid = fopen('file.txt');
textscan(fid, '%*s%*s%s');  % loads only the third column
fclose(fid);

This assumes there are exactly three columns in your file. If you have many more columns, you will want:

fid = fopen('file.txt');
    twocols = textscan(fid,'%*s%*s%s%*[^\n]');
fclose(fid);

Upvotes: 1

Related Questions