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 ビュー (過去 30 日間)
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.
  1 件のコメント
Fedilberto Gonzalez
Fedilberto Gonzalez 2021 年 11 月 22 日
x = contourf(:,1);
y = contourf(:,2);
z = contourf(:,3);
[X,Y] = meshgrid(x,y) ;
zg = griddata(x,y,z,X,Y) ;
[Cx, h] = contourf(X,Y,zg,15);

サインインしてコメントする。

採用された回答

Benjamin Kraus
Benjamin Kraus 2021 年 11 月 23 日
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');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by