如何从Matlab中的文本文件读取矩阵 [英] how to read a matrix from a text file in matlab

查看:1051
本文介绍了如何从Matlab中的文本文件读取矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,该文件具有数字(整数)值的500 columns500 rows.该行中的每个元素都由一个制表符分隔.我想将此文件读取为matlab中的矩阵.示例(我的文本文件是这样的):

I have a text file which has 500 columns and 500 rows, of numerical(integer) values . Every element in the row is separated by a tab. I want to read this file as a matrix in matlab. Example(my text file is like this):

 1 2 2 1 1 2 
 0 0 0 1 2 0
 1 2 2 1 1 2 
 0 0 0 1 2 0

然后在matlab中读取此文本文件作为矩阵(a[])后,我想做transpose. 救救我.

And after reading this text file as a matrix (a[]) in matlab I want to do transpose. Help me.

推荐答案

您可以使用importdata. 像这样:

You can use importdata. Something like:

filename = 'myfile01.txt';
delimiterIn = '\t';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
A_trans = A';

如果文件没有任何杂音,则可以跳过标题行.(这是实际数据开始之前的行数)

You can skip headerlines if your file does not have any haeder.. (It is the number of lines before the actual data starts)

摘自Matlab文档, improtdata

Taken from Matlab documentation, improtdata

这篇关于如何从Matlab中的文本文件读取矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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