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

3 Ansichten (letzte 30 Tage)
Saeid am 26 Apr. 2024
Kommentiert: Mathieu NOE am 2 Mai 2024
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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Mathieu NOE am 29 Apr. 2024
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 KommentareKeine anzeigenKeine ausblenden
Saeid am 2 Mai 2024
Thanks Mathieu!
Mathieu NOE am 2 Mai 2024
as always, my pleasure !!

Melden Sie sich an, um zu kommentieren.

### Kategorien

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

R2024a

### Community Treasure Hunt

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

Start Hunting!

Translated by