Analysing data that meets conditions

2 views (last 30 days)
Christopher Hall
Christopher Hall on 24 Apr 2015
Edited: dpb on 27 Apr 2015
Hi all,
I am trying to analyse data from an FEM software. The data relates to node positions and then a velocity value [x,y,u].
I am trying to analyse sectors of the 2D domain which is 5000m x 2000m.
For each sector I want to analyse a 1m x 113m area and then average all the nodes within that sector to form an overall u.
I don't quite know how to tackle this problem, I have been trying for a few days and can't quite get the scripts to work.
I specifically want to know if it is possible to scan through data looking for specific nodes which are within (1 <= x <= 2),(10<=y<=123) and then average them and then start building up a library of u values for each sector.
I would greatly appreciate anyones input.
Kind Regards,
Christopher
  2 Comments
per isakson
per isakson on 24 Apr 2015
Could you provide a small sample of the FEM data? A dozen nodes or so.
Christopher Hall
Christopher Hall on 25 Apr 2015
Edited: Christopher Hall on 25 Apr 2015
Hi,
Please see attached.
Data is in 4 columns. X,Y,u,v
if true
% code
end
x y u v
2694.423447 130.70604 5.09691 -1.90E-32
2737.960167 127.0907625 -3.29116E-33 -3.24E-33
2781.495344 122.7349759 5.62236 -1.63E-33
2825.029179 117.7478191 -3.91898E-38 -1.31E-33
2868.561884 112.238398 4.29103 0.678088
3086.215982 80.67439978 5.81633 1.46921
3042.685676 87.15933541 5.99576 -8.40E-36
2999.155342 93.66722695 3.33074 0.422837
2955.624747 100.0890545 -4.50664E-36 -9.63E-34
2912.093668 106.3157911 5.98022 1.62858
3129.746501 74.32143915 6.31439 1.82298
3173.277481 68.20947744 6.28565 -2.05E-36

Sign in to comment.

Accepted Answer

dpb
dpb on 25 Apr 2015
"I specifically want to know if it is possible to scan through data looking for specific nodes which are within (1 <= x <= 2),(10<=y<=123) and then average them...
Presume you've read the file and have the 2D array data
idx=iswithin(data(:,1),1,2) & iswithin(data(:,2),10,123); % select the condition; idx-->logical
means=mean(data(idx,:)); % average over each column of those values (*)
(*) I don't know for certain what "them" above refers to, specifically, so I just averaged all four columns of data for the selected combination of x/y coordinates including the coordinates.
iswithin is my helper function (a little syntactical sugar to make the higher level code a little more legible; it's nothing fancy) --
>> type iswithin
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
>>
Put it in an m-file named iswithin.m and somewhere on the Matlab path matlabpath -- I have a "utilities" subdirectory for such generally useful things.
  3 Comments
dpb
dpb on 25 Apr 2015
Edited: dpb on 27 Apr 2015
I don't follow the explanation of the wish...give a small example of inputs/desired outputs. "at a height change of 1 unit" relative to what? The above selects the combination between the two limits; do you mean you want to repeat for a different set of limits, maybe?
ADDENDUM
OK, rereading a little more slowly and going back to the original question again, I guess I do follow that you do want to move the range of y values for a given range of x. I'd probably help out the lookup a little -- for the purpose of averaging it makes no difference on ordering. So, once you've selected a subset of x-coordinate values, sort that on y to place them all in contiguous group rather than scattered around. Then can simply find just the first and last of the range instead of each individually; should be at least a little faster.
Since the y range is 2000m and the initial ending selection point is 113 but you're wanting to step in unit increments, you've got a set of
N = 2000-113+1 = 1888
averages to compute, but looking at the sample subset of data it looks like the minimum dy is >3m so it would seem that a 1m step would result in an average of 3-4 sets being identical in that the selected points wouldn't change between subsequent groups until there's been a total difference of 3 or 4m. If within the grid there is a local area with finer mesh, that would change that conclusion, of course.
Anyway, those details aside I would probably just preallocate a vector for the right length as computed above and then just loop thru but use find instead of logical addressing since with the ordering it should be faster.
That would be something like
dat=data(iswithin(data(:,1),1,2),:); % select on x first
datsort=sortrows(dat,2); % now sort on y
for i=1:N
i1=find(datsort(:,2)>=lim1,1,'first'); % get the start
i2=find(datsort(:,2)<=lim2,1,'last'); % and index for this group
lim1=lim1+1;
lim2=lim2+1;
ubar(i)=mean(datsort(lim1:lim2,3));
end
The iswithin lookup probably isn't quite as fast as the find(x,1,'first|last') option but since it only occurs once it's a small price to pay. But, if the end goal is for both x- and y-, that'd probably be a worthwhile optimization.
As above, you can also keep a running average of the y-values if that's of interest/use, the x average for this subset is fixed of course by the initial selection.
Christopher Hall
Christopher Hall on 26 Apr 2015
Hi,
Yes exactly. I want to loop through all the y values for each x position of the entire domain.
I want to take high resolution steps through every possible rectangular (1x113) grid combination. so if my domain is 2x114 i want to get 4 regions.
There would be two sectors @ 0<=x<=1 , sector 1 0<y<=113 , sector 2 1<y<=114 and @ 1<x<+2, sector 3 0<y<=113 , sector 4 1<y<=114

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!