필터 지우기
필터 지우기

parse file data (.spc) into multiple variables

조회 수: 1 (최근 30일)
katerina
katerina 2014년 6월 26일
답변: katerina 2014년 6월 26일
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!

답변 (1개)

katerina
katerina 2014년 6월 26일
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.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by