如何将.txt文件加载到matlab定义的数组结构中?

问题描述 投票:0回答:1

我有一个.txt文件,每列代表3d point (x,y,z)two properties (a,b)

1.7 5.5 -3.62   0.6 10.3    []
1.0 5.5 -3.21   0.9 12.4    []
1.2 5.9 -3.25   0.5 13.9    []
1.3 5.5 -3.19   0.9 15.9    []
1.0 5.2 -3.13   0.3 17.4    []
1.7 5.9 -3.07   0.5 19.6    []
2.5 5.5 -3.01   0.9 20.9    []
2.5 5.2 -3.95   0.4 22.9    []

我想加载文件,如

myStruct.X, myStruct.Y,myStruct.Z,myStruct.A,myStruct.B

如何做

matlab
1个回答
0
投票

使用dlmread将文本文件的内容读取到某个数组,例如dlmread。这行得通,因为这里只有数值。警告:从文档开始,从MATLAB R2019a开始:

A不推荐。请改用dlmread

然后,对多个字段和值使用正确的readmatrix命令,如下所示:

struct

这将导致这样的输出(缩短):

struct

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.