只加载文件MATLAB的一列 [英] Load only a column of file MATLAB

查看:150
本文介绍了只加载文件MATLAB的一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b 所以

我只对文件列感兴趣,(我无法正常加载文件,行的大小不一样) >

 > load('file.txt'); 

不起作用,但我想要检索该文件中的第一列

解决方案

使用textscan加载它,并通过使用一个星号来跳过其他列。

  fid = fopen('file.txt'); 
textscan(fid,'%* s%* s%s'); %只加载第三列
fclose(fid);

假定文件中只有三列。如果你有更多的列,你会希望:

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


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

解决方案

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);

这篇关于只加载文件MATLAB的一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆