Converting a three-column set of data to xyf matrix suitable for a contour plot
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
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')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!