Getting rid of data that does not meet conditions: Poincare section
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Turlough Hughes
2019년 11월 11일
편집: Turlough Hughes
2019년 11월 11일
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
Turlough Hughes
2019년 11월 15일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!