Selecting points at and around peaks in 2D

3 views (last 30 days)
Jerry Yeung
Jerry Yeung on 1 Mar 2022
Edited: William Rose on 1 Mar 2022
Hello. I'm trying to select the data points at and around the peaks (see attached figure) for further calculations, and I don't see a simple way of doing so. The data in question will always be a 2D plane with a different number of x and y points, and the data points of interest will always be a series of peaks along a curved line.
I'm hoping to obtain a function for the envelope (an ellipse function perhaps) which encompasses all the peaks, the reason being I'm hoping to redo the calcution of only those points of interest with a finer mesh. Otherwise I would've just found the locations of the peaks and plugged that into my original code. Any advice is appreciated.
Edit: I've just realised I could try fitting an ellipse function to the peaks and get a function for the envelope this way, but the question remains, given the envelope (2 ellipse functions probably), how can I select only the data points which fall within this envelope?

Answers (1)

William Rose
William Rose on 1 Mar 2022
Since you want a rnage of values surrounding the ellipse, it seems you are still looking for a 2-dimensional data set. Waht do you imagine for the structure of the desired dataset?
This code makes a data set which is maximal along an ellipse. We can use it to test out methods to do what you want.
N=100; x=0:N; y=0:N; [X,Y]=meshgrid(x,y);
Z=zeros(size(X));
a=80; b=60; %ellipse semimajor axes
for i=0:N, for j=0:N, Z(i+1,j+1)=1/(((i/a)^2+(j/b)^2-1)^2+.1); end,end %compute z values
surf(X,Y,Z,'EdgeColor','none'); colorbar; view(0,90)
Now let's select points in a band near the ellipse.
  2 Comments
William Rose
William Rose on 1 Mar 2022
Edited: William Rose on 1 Mar 2022
[edit: corrected typo]
Run the code in my previous answer. I modified the code so that vectors x and y have different lengths. This assures that arrays X,Y,Z are not square, which makes the code more general, and which helps assure that, if there is a mix-up of X and Y axes, we will know it, because it will causese an error. I did this because surf() plots array Z with the first index as the row, or vertical coordinate, and the second index being the column, or horizontal coordinate. We are used to thinking of X first, then Y. Therefore this behavior of surf() can cause confusion. I also chose different values for a and b, to help us see that the ellipse is oriented as expected.
M=100; N=110; x=0:M; y=0:N; [X,Y]=meshgrid(x,y);
Z=zeros(size(X));
a=80; b=90; %ellipse semimajor axes along x,y respectively
for i=0:N
for j=0:M,
Z(i+1,j+1)=1/(((i/b)^2+(j/a)^2-1)^2+.1); %compute z values
end
end
surf(X,Y,Z,'EdgeColor','none'); colorbar; view(0,90)
xlabel('x'), ylabel('y'), zlabel('z');
Next, select a subset of points that are within a specified distance of the ellipse:
Zs=Z(abs(sqrt(X.^2/a^2+Y.^2/b^2)-1)<.05);
Xs=X(abs(sqrt(X.^2/a^2+Y.^2/b^2)-1)<.05);
Ys=Y(abs(sqrt(X.^2/a^2+Y.^2/b^2)-1)<.05);
This produces three 1D arrays, with the Z, X, and Y coords of the selected points.
Plot the points:
figure; plot3(Xs,Ys,Zs,'bx'); grid on; view(0,90)
xlabel('x'); ylabel('y'); zlabel('z');
This demontsrates how to select the subset of points that are near the ellipse.
William Rose
William Rose on 1 Mar 2022
Edited: William Rose on 1 Mar 2022
Here is an improvement on my previous code. I am replacing the nested for loops with a single command. This is more elegant, and should execute faster, although the speed improvement is probably not important unless your problem is really large. Results are identical to results from my previous comment. This is different from the results in my initial answer, for the reason I explained in the comment, having to do with different length vectors for x and y.
M=100; N=110; x=0:M; y=0:N; [X,Y]=meshgrid(x,y);
Z=zeros(size(X));
a=80; b=90; %ellipse semimajor axes along x,y respectively
Z=1./(((X/a).^2+(Y/b).^2-1).^2+.1); %compute z values
surf(X,Y,Z,'EdgeColor','none'); colorbar; view(0,90)
xlabel('x'), ylabel('y'), zlabel('z')

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!