Filter löschen
Filter löschen

Interpolation of a point from contourf

4 Ansichten (letzte 30 Tage)
Tal Shavit
Tal Shavit am 1 Aug. 2022
Beantwortet: Saarthak Gupta am 14 Sep. 2023
I need to interpolate the x,y coordinates for Z=1 in the following contour:
the point 1 doesn't exist in my data.
and my data:
x:
y:
I have figured the existing point closest to one, but I need 1 exactly.
Thank you very much!

Antworten (1)

Saarthak Gupta
Saarthak Gupta am 14 Sep. 2023
Hi,
I understand you are trying to find the X and Y values for the level Z = 1. According to the query, the z-coordinates you have given as input to the ‘contourf’ function do not contain 1.
You can use a list of levels where the contour lines will be displayed and include 1 in it.
Refer to the following code:
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X) + cos(Y);
% Specify 10 levels, and explicitly include 1 in the list of levels
levels = [linspace(-pi/2,1,4) 1 linspace(1,pi/2,5)];
M = contourf(X,Y,Z,levels);
% To check if 1 is part of the levels, get the list of levels from the contour matrix
levelList = findAllLevels(M);
function levels = findAllLevels(M)
% This helper function extracts all levels/heights from the contour matrix returned by contourf
n=size(M,2);
j=1;
i=1;
while i+M(2,i)+1<n
i = i+M(2,i)+1;
levels(j) = M(1,i);
j = j+1;
end
end
This would ensure a contour line is plotted at Z = 1, and the x and y coordinates at this contour line can be obtained through the contour matrix ‘M’. You can observe the same by inspecting ‘M’ in the editor window:
Please refer to the following MATLAB documentation for further reference:

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by