Converting a three-column set of data to xyf matrix suitable for a contour plot
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Mathieu NOE
le 29 Avr 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!