如何从 MATLAB 中的文本文件创建矩阵? [英] How do you create a matrix from a text file in MATLAB?
问题描述
我有一个有 4 列的文本文件,每列有 65536 个数据点.行中的每个元素都用逗号分隔.例如:
I have a text file which has 4 columns, each column having 65536 data points. Every element in the row is separated by a comma. For example:
X,Y,Z,AU
4010.0,3210.0,-440.0,0.0
4010.0,3210.0,-420.0,0.0
etc.
所以,我有 65536 行,每行有 4 个数据值,如上所示.我想将其转换为矩阵.我尝试将数据从文本文件导入到 Excel 文件中,因为这样很容易创建矩阵,但我丢失了一半以上的数据.
So, I have 65536 rows, each row having 4 data values as shown above. I want to convert it into a matrix. I tried importing data from the text file to an excel file, because that way its easy to create a matrix, but I lost more than half the data.
推荐答案
如果文件中的所有条目都是数字,则可以简单地使用 a = load('file.txt')
.它应该创建一个 65536x4 的矩阵 a
.它甚至比 csvread
If all the entries in your file are numeric, you can simply use a = load('file.txt')
. It should create a 65536x4 matrix a
. It is even easier than csvread
这篇关于如何从 MATLAB 中的文本文件创建矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!