I have a contourf function constituted by x, y and z vectors (It is a large matrix). Then, I would like to find the x, y and z values corresponding to certain x and y vectors.

2 visualizaciones (últimos 30 días)
I was plotting something with contourf. I created a beautiful picture with many x, y and z vectors. Then, I have certain x and y values which I would like to know their z value corresponding to the contourf.
For instance, below you can find the values used to create the contourf graph. However, I am not able to obtain the x ,y z related to the x and y points that I also attached.
Could you kindly help me please? I would be really grateful.

Respuesta aceptada

Benjamin Kraus
Benjamin Kraus el 23 de Nov. de 2021
I'm not sure I completely understand your question, but I think you are misusing meshgrid in your code example above.
Does this do what you want?
% Read the `contourf.txt` and `x and y points that I am interested in.txt` points into MATLAB
data = readmatrix('contourf.txt');
query = readmatrix('x and y points that I am interested in.txt');
x = data(:,1);
y = data(:,2);
z = data(:,3);
xq = query(:,1);
yq = query(:,2);
% Use griddate to determine the value at each of the query x/y points.
[Xq,Yq, zq] = griddata(x,y,z,xq,yq);
% If I understand correctly, the value of zq is what you are looking for.
% The rest of this code is just to visualize the results.
% Create X/Y grids based on the range of the input data.
n = 50;
[X,Y] = meshgrid(linspace(min(x),max(x),n), linspace(min(y),max(y),n));
% Sample the X/Y grid using griddate.
Z = griddata(x,y,z,X,Y);
% Draw the contour lines overlayed on a surface plot.
surf(X,Y,Z,'EdgeColor','none')
hold on
contour3(X,Y,Z,15,'EdgeColor','k')
% Overlay the original data points
plot3(x,y,z,'k.');
% Overlay the query data points.
plot3(xq,yq,zq,'ro');

Más respuestas (0)

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by