The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: parse file data into multiple variables
Replies: 1   Last Post: Jun 27, 2014 2:38 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 3
Registered: 6/25/14
parse file data into multiple variables
Posted: Jun 26, 2014 5:03 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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!

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.