I would like to assign input data to 2 different structs, depending on a condition (Matlab). What is the best way to do this?
FILE points.dat
% Point ID X Y CODE
Station1 2.2 4.5 0
Station2 5.1 6.7 0
Station3 7.3 3.2 1
Station4 2.1 5.0 1
Goal: If code = 0, assign to struct A. If not, assign to struct B.
Here's what I tried. Just a shot in the dark, really.
fid = fopen('points.dat');
C = textscan(fid, '%s %f %f %f', 'CommentStyle','%');
fclose(fid);
if (C{4} == 0)
A = struct('id',C{1}, 'x', num2cell(C{2}), 'y', ...
num2cell(C{3}), 'code', num2cell(C{4}));
else
B = struct('id',C{1}, 'x', num2cell(C{2}), 'y', ...
num2cell(C{3}), 'code', num2cell(C{4}));
end