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

4 Ansichten (letzte 30 Tage)
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 Kommentare
Turlough Hughes
Turlough Hughes am 11 Nov. 2019
Would you prefer to interpolate to y=0?
jacob Mitch
jacob Mitch am 11 Nov. 2019
I believe that would yield more accurate results but I'm unsure on how I would go about that

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 11 Nov. 2019
Bearbeitet: Turlough Hughes am 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 Kommentare
jacob Mitch
jacob Mitch am 14 Nov. 2019
Hi thanks, I also tried a different approach if this makes sense but am I able to expand on this
New=zeros(1,3);
k=0;
for i=1:length(Data)
if abs(Data(2,i))<.1 && Data(1,i)>0 %finds all x>0 y+-0.1 either side of 0
k=k+1;
New(1,k)=Data(1,i);
New(2,k)=Data(2,i);
New(3,k)=Data(3,i); %indexes to z
Am I doing something similar to you. Sorry for the late reply
Turlough Hughes
Turlough Hughes am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by