Contour Plot gives error

8 次查看(过去 30 天)
figure
x = ICE_m_f_dot_map_temp_w; % 1*140 array of values
y = ICE_m_f_dot_map_temp_T; % 1*140 array of values
[X,Y]=meshgrid(x,y);
z = ICE_m_f_dot_map_temp; % 1*140 array of values
contour3(X,Y,z)
With the above code I am trying to plot contours but I recieve this error.
Error using contour3 (line 44)
Z must be at least a 2x2 matrix.
Error in ME7384AU21_Fahim_HW2 (line 97)
contour3(X,Y,z)

采纳的回答

Walter Roberson
Walter Roberson 2021-9-25
N = 200; %grid refinement
x = ICE_m_f_dot_map_temp_w; % 1*140 array of values
y = ICE_m_f_dot_map_temp_T; % 1*140 array of values
z = ICE_m_f_dot_map_temp; % 1*140 array of values
minx = min(x); maxx = max(x);
miny = min(y); maxy = max(y);
[X, Y] = meshgrid(linspace(minx, maxx, N), linspace(miny, maxy, N));
F = scatteredInterpolant(x(:), y(:), z(:));
Z = F(X, Y);
contour3(X, Y, Z);
  2 个评论
Muhammad Qaisar Fahim
Thanks Walter but this is in 3d I want it in 2d. Here
x = ICE_m_f_dot_map_temp_w; % 1*140 array of values
Should be on x Axis
y = ICE_m_f_dot_map_temp_T; % 1*140 array of values
Should be on y Axis
z = ICE_m_f_dot_map_temp; % 1*140 array of values
I need 20 contours from these 140 values that would form a constant contour haning constant value on that particular contour
Walter Roberson
Walter Roberson 2021-9-25
Your original code uses contour3 which is for 3d representation. If you want 2d then use contour() or contourf instead.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2021-9-25
You cannot use contour with column data. You can use scatter to plot data or if your data is gridded consider using griddata or reshaping the data as shown in the blow link:
  2 个评论
Muhammad Qaisar Fahim
Thanks KSSV. I need to plot the contour not the scatter plot. But data is given as colomn vectors. Then how could I tailor that it can be used to create contour plot?
KSSV
KSSV 2021-9-25
编辑:KSSV 2021-9-25
I have given a link. Read that.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by