Converting a three-column set of data to xyf matrix suitable for a contour plot

4 ビュー (過去 30 日間)
Saeid
Saeid 2024 年 4 月 26 日
コメント済み: Mathieu NOE 2024 年 5 月 2 日
I have a set of data (the output of a CFD calculation) that consists of three columns x and y showing location and a third column that we call f which contains the values of the variable calculated for every specific xy location. I want to convert this array to a 2D matrix where x and y are now in the horizontal and vertical directions. Some data points simply do not exist because they are outside of the domain boundaries.
So basically, what I need to do is this (where the black cells are the ones for which the original dataset has no values.):
And since we are dealing with a very large dataset here, it is much more preferred to avoid using a loop.

採用された回答

Mathieu NOE
Mathieu NOE 2024 年 4 月 29 日
hello
see example below, the x,y,z are dummy data - use your own data instead
% create somme dummy data
z = peaks(20);
% convert to scatter points
z = z(:);
x = rand(size(z));
y = rand(size(z));
% main code
F = scatteredInterpolant(x, y, z);
xv = linspace(min(x), max(x), 100);
yv = linspace(min(y), max(y), 100);
[X,Y] = meshgrid(xv, yv);
Z = F(X, Y);
% plot
figure
contour(X, Y, Z)
grid
xlabel('X')
ylabel('Y')
zlabel('Z')
colorbar('vert')
colormap('jet')
  2 件のコメント
Saeid
Saeid 2024 年 5 月 2 日
Thanks Mathieu!
Mathieu NOE
Mathieu NOE 2024 年 5 月 2 日
as always, my pleasure !!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by