how to get some values from many text files and put the into the calculation
2 次查看(过去 30 天)
显示 更早的评论
hello, I have many text files like i shared below and their names are data_01, data_02 and data_03...i found the way of the finding avarage value of Area, xbar,ybar,IXXw and IYYw which is in the below but i just cannot use those values in order to put calculation.for example i want to define 'n' is a xbar(avarage) / 2 but when i try to do that i got the result like a matrix but i dont want it. i just want one value which is the avarage of xbar.how can i do that?
%variables to average over
AveVariables = {'Area', 'xbar', 'ybar', 'IXXw', 'IYYw'};
AveVariables = lower(AveVariables); %remove case
Files = dir('data*.txt'); %get all dataXX files
nFiles = length(Files);
AllData = NaN( nFiles, length(AveVariables)); %variables for each file
for k = 1:nFiles;
File = Files(k).name;
str = fileread(File); %read file into string
pat = '\(*(?<var>[A-Z]+)\)*\s+\=\s+(?<val>[0-9\.\-]+)'; %define pattern
%search pattern is:
%[series of letters, possibly surrounded by parens] = [signed decimal number]
variables = regexpi(str, pat, 'names'); %match pattern
values = {variables.val};
vars = lower({variables.var});
[tf,loc]=ismember( AveVariables, vars); %compare to target variables
values = str2double(values(loc(tf))); %convert to numeric
AllData(k,tf)=values; %add to AllData matrix
end
AveData=nanmean(AllData,1); %average over files
============================================================
Information listing created by : T40118
Date : 29.08.2013 11:07:12
Current work part : FA00AAC41319/002
Node name : tofdsk03221
============================================================
Work Part FA00AAC41319/002 : 08/29/13 11:07
Information Units kg - mm
Perimeter = 765.13878188660
Area = 11875.0
First Moments
MY = -109375.0
MX = -1062500.0
Center of Mass
Xbar = -9.21052631578950
Ybar = -89.4736842105260
Moments of Inertia (Work)
Ixxw = 110677083.333330
Iyyw = 25716145.8333330
Moments of Inertia (Centroidal)
Ixx = 15611293.8596490
Iyy = 24708744.5175440
Moment of Inertia (Polar)
= 40320038.3771930
Product of Inertia (Work)
Pxyw = 20507812.50
Product of Inertia (Centroidal)
Pxy = 10721628.2894740
Radii of Gyration (Work)
Rgxw = 96.5410557151540
Rgyw = 46.5356871168630
Radii of Gyration (Centroidal)
Rgx = 36.2578994481410
Rgy = 45.6150893940230
Radii of Gyration (Polar)
= 58.2698176830530
0 个评论
采纳的回答
Walter Roberson
2013-9-15
What is the final size of AllData ?
It appears to me that you would be wanting mean(AllData(:,2)) for the average xbar.
Are you currently taking mean(AllData) ? If so then the output row should be in the order of your variables.
Just make sure you do not use mean(AllData,2) as that would average along the rows instead of down the columns.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!