parse file data (.spc) into multiple variables

1 view (last 30 days)
katerina on 26 Jun 2014
Answered: katerina on 26 Jun 2014
i have an array of structs (of nested structs) into which i need to store the file information. it's a format where i have to read in one piece of information at a time, like this:
Shafts 2
HardPoint0X -512.343
HardPoint0Y -551.322
HardPoint0Z 9.479
HardPoint1X -469.2
HardPoint1Y -549.1
HardPoint1Z 57.5
so just for this snippet i have to fill the Shafts and the structures HardPointX (as well as Y and Z) into my program. my structure declaration (shortened) is:
data(15) = struct(Shafts,[],HardPointX,struct([]),HardPointY,struct([]), etc..)
so i want hard points to be smaller structures but for shafts to be just one value.
here's how i read in currently:
for i = 1:num_files
file = fopen([pathName fileName{1,i}],'r');
data(i).Shafts = fscanf(file,'Rev 1.0\nShafts%d',1);
for n = 1:10
data(i).HardPointX.n = fscanf(file,'*%s%f',1);
data(i).HardPointY.n = fscanf(file,'*%s%f',1);
data(i).HardPointZ.n = fscanf(file,'*%s%f',1);
n = n + 1;
so what i'm trying to do is skip past the strings and only get the numbers one at a time. but what's happening to my output during debug is that only Shafts gets its value, and then nothing else later does. i've tried with '\n' in the file reading, but that doesn't seem to make a difference. any suggestions?
thank you!

Answers (1)

katerina on 26 Jun 2014
i have a little more info now. i just did some testing (stored the whole file into one variable), and it almost seemed like it was reading my %s as %c, because it showed specific values for each character in the file, instead of putting the chars together as strings. not sure if this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!