Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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 ]
katerina

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;
end
end
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]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.