0

我正在尝试使用成员 ID、X 坐标和 Y 坐标创建一个名为“points”的结构。从文件中扫描数据的最简单方法是什么?我正在使用 textscan,但到目前为止它并没有做我想要的。

FILE points.dat
StationA    2.2   4.5
StationB    5.1   6.7
StationC    7.3   3.2


fid = fopen('points.dat');
C = textscan(fid, '%s %f %f');
fclose(fid);

points = struct('id',C{1},'x',C{2},'y',C{3})

检查点(1)返回以下内容。所有 x 和 y 值都存储在每个点中。

id: 'StationA'
 x: [3x1 double]
 y: [3x1 double]

任何帮助表示赞赏。

4

1 回答 1

0

它应该是这样的:

points = struct('id',C{1}, 'x', num2cell(C{2}), 'y', num2cell(C{3}));
于 2014-03-11T05:56:59.993 回答