Load only a column of file MATLAB
I am interested only in a column of a file, (I can not load the fi开发者_JS百科le 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
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);
精彩评论