how can i draw contourf plot

조회 수: 9 (최근 30일)
윤혁
윤혁 2024년 9월 14일
댓글: Angelo Yeo 2024년 9월 14일
I'm going to make a plot like this picture.
I interpolated the data using the interp1 function. However, contourf can only contain values of 2*2 or more, so the function cannot be executed. How do I solve this?
  댓글 수: 1
Angelo Yeo
Angelo Yeo 2024년 9월 14일
Can you share your data and script that you have tried with so far?

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush
Ayush 2024년 9월 14일
Hi 윤혁
If your data is too sparse, consider increasing the number of points used in interpolation. You can do this by defining a finer grid for interpolation. Here is the sample code for this technique:
% Sample data
x = 1:10;
y = sin(x);
% Define a finer grid for interpolation
xq = 1:0.1:10;
% Interpolate the data
yq = interp1(x, y, xq, 'spline');
% Create a meshgrid for contour plot
[X, Y] = meshgrid(xq, xq);
Z = sin(X) .* cos(Y); % Example function for Z values
% Ensure Z has dimensions 2x2 or more
if min(size(Z)) < 2
error('Z must be at least 2x2 in size');
end
% Create contour plot
contourf(X, Y, Z);
colorbar;
title('Interpolated Contour Plot');
xlabel('X-axis');
ylabel('Y-axis');
I hope this was helpful.

카테고리

Help CenterFile Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by