# Getting rid of data that does not meet conditions: Poincare section

12 views (last 30 days)
jacob Mitch on 11 Nov 2019
Commented: Turlough Hughes on 15 Nov 2019
If I have a data array where the first row corresponds to the x axis second to the y axis and third row to the z axis. I want to only consider x>0 data and then finding all the points in which y changes from positive to negative and negative to positive. For example if I have
Data=[-2,-3,4,2,5,5,-1; %x values
-1,2,3,-1,5,6,-1; %y values
1,1,1,1,1,1,1] % z values
%I want to only consider x>0 and corresponding y,z points so I get
NewData=[4,2,5,5;
3,-1,5,6;
1,1,1,1 ]
% and then finding all the points where that pass through y=0 which I believe results in
New2Data=[2,5;
-1,5;
1,1]
Essentially I believe I am dealing with a Poincare section finding all the points that pass through P = {x, z : y = 0, x > 0} and finding all the points that pass through P
Thanks for the help in advance
##### 2 CommentsShowHide 1 older comment
jacob Mitch on 11 Nov 2019
I believe that would yield more accurate results but I'm unsure on how I would go about that

Turlough Hughes on 11 Nov 2019
Edited: Turlough Hughes on 11 Nov 2019
You can get your data where x>0 as follows:
ND=Data(:,find(Data(1,:) > 0)) % x > 0, for brevity I just call this ND.
you can then get pairs of data points that are either side of y=0 as follows:
idx1 = find(ND(2,1:end-1) > 0 & ND(2,2:end) < 0 | ND(2,1:end-1) < 0 & ND(2,2:end) > 0);
idx2 = sort([idx1+1 idx1]);
pairs = ND(:,idx2);
New2Data=ND(:,idx1+1) %also
Now, interp1() allows you to interpolate values at y=0 but it does so by treating the input data as a 1-D function, i.e. any value of x interpolated to y=0 would yield the same answer. I think you're probably looking for local linear interpolation each pair of two points only. So, I used the interp1 function iteratively on each pair:
x = pairs(1,:); y = pairs(2,:); z = pairs(3,:);
for c=1:length(y)/2
xi(1,c) = interp1(y(2*c-1:2*c),x(2*c-1:2*c),0);
zi(1,c) = interp1(y(2*c-1:2*c),z(2*c-1:2*c),0);
end
New3Data = [xi;zeros(size(xi));zi] % with a larger dataset I would expect variation of x and z in your P section.
Let me know if this is what you are looking for.
##### 2 CommentsShowHide 1 older comment
Turlough Hughes on 15 Nov 2019
Well they're two different approaches, mine interpolates to y=0 while yours finds points within a tolerance of y=+/-0.1, but what you're doing looks like it will work. You could actually do this without a for loop:
idx=ones(3,1) * abs(Data(2,:))<.1 & Data(1,:)>0;
New=reshape(Data(idx),3,[]);
How do you want to expand on this? If you want to include interpolations with this approach it could be tricky.