It should be like this:
points = struct('id',C{1}, 'x', num2cell(C{2}), 'y', num2cell(C{3}));
Question
I am trying to create a struct called "points" with members ID, X coordinate, & Y coordinate. What is the simplest way to scan in the data from a file? I'm using textscan, but it's not doing what I want so far.
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})
Checking points(1) returns the following. All the x & y values are stored in each point.
id: 'StationA'
x: [3x1 double]
y: [3x1 double]
Any help appreciated.
Solution
It should be like this:
points = struct('id',C{1}, 'x', num2cell(C{2}), 'y', num2cell(C{3}));