How do determine the maximum and minimum point form origin on a contour graph

I have created a contour graph from the folloing code, where C_100030_alt173 is my raw data. I will return a contour plot with points containing (x, y, level). How do I find the max. and min. point from the origin (0,0). ie. how do i extract xy values for all points and do a simple (x^2+y^2)^1/2 calculation and identify the max. and min.
Thank you so much
x=(-1:1/512:1);
C_100030_alt173
c1P5_alt173=reshape(CON,[1025,1025]);
a=[0,0];
v1=[0.5,0.5];
v2=[0.11,0.11];
contour(x,x,c1P5_alt173,v1,EdgeColor="black");
hold on
contour(x,x,c1P5_alt173,v2,EdgeColor="blue");

 Accepted Answer

Not sure exactly what you want but contour function can give you interpolated x-y positions for a specific level. From there you can use a simple calculation to find the max distance to origin for that spefic level.
Z = peaks;
% get x-y locations of points corresponding to desiredLevel
desiredLevel = 1.949;
p = contourc(Z,desiredLevel*[1 1]);
% remove x y positions outside of [0 50] range
p(:,p(1,:)>50|p(2,:)>50) = [];
% get max distance
dist = sqrt(p(1,:).^2+p(2,:).^2);
maxDistIdx = find(dist==max(dist));
% draw contour graph
[M,c] = contourf(Z);xlim([0 50]);ylim([0 50])
hold on
% draw each point for the desiredLevel and the largest distance for that level
plot(p(1,:),p(2,:),'rx',...
[0 p(1,maxDistIdx)],[0 p(2,maxDistIdx)],'r-','LineWidth',2)
hold off

7 Comments

Thank you for the answering the question
As the below plot, each point on the graph has a X and Y value. I would like to extract all the xy values to calculate the min and max distance from (0,0)
If you only want x-y values for the blue and black line, you can call the countourc() function with their respective levels (for blue it seems like 0.1154). This will give you not every x-y points since there are infinite number of x-y values on those curves, but will give you sufficiently high number of x-y points.
Just a small question, say my raw data is arranged into a 1025*1025 matrix as c1P5_alt173, how do I formulate the contourc() to aquire all levels, or say limit the level range from 0<level<1. Thank you a lot
p = contourc(x,x,c1P5_alt173);
This should work for you;
levelRange = [0 1];
p = contourc(x,x,c1P5_alt173,levelRange);
However I do not think using the 'x' variable for both X and Y axis is correct. Dont you have seperate 'y' array as well?
no i don't have a y array, the plot is created through the following commend
contour(x,x,c1P5_alt173,v1,EdgeColor="black");
Then still
p = contourc(x,x,c1P5_alt173,levelRange);
would work for you.
You can read more and see more examples on the countourc function here.
thank you very much for all the explanation.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 8 Apr 2024

Commented:

on 9 Apr 2024

Community Treasure Hunt

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

Start Hunting!