在 Matlab 中绘制网格时尺寸不一致错误
Inconsistent dimension error when plotting mesh in Matlab
我是 Matlab 的新手,我想绘制一个网格。我的坐标是:
x = [30 34 38 40 44 48 50]
y = [1:5:20]
Z = [9.1 8.5 7.83 7.54 7.07 6.61 6.49 ;
14.5 8.96 8.21 7.71 7.07 6.61 6.4;
13.37 13.4 10.2 9.4 9 7.3 7.9;
12.09 12 12.14 11.96 13.58 14.12 14.311;
14.97 10.77 11.87 12.4 13.62 14.19 14.94]
我尝试在 Matlab 中绘制它时出现以下错误:
Data point coordinates have inconsistent dimension.
您确实 尺寸不一致 因为您需要 y
中的 5 个元素。您还需要一个矩阵 Z
,而不是向量。
以下应该可以帮助您入门:
y = [0:5:20]
%// reshape z in case z is a vector
z = reshape(Z,numel(y),numel(x))
figure(1)
%// mesh(x,y,z)
surf(x,y,z) % colored mesh
检查数据大小并根据需要调整整形!
一般来说,如果 X
和 Y
是向量,length(X) = n
和 length(Y) = m
,其中 `[m,n] = size(Z)v.
你的情况:
length(x)
7
length(y)
4
但是
size(Z)
1 35
所以你需要重塑Z
。
做:
x = [30 34 38 40 44 48 50]
y = [0:5:20]
Z = [9.1 8.5 7.83 7.54 7.07 6.61 6.49 ; 14.5 8.96 8.21 7.71 7.07 6.61 6.4; 13.37 13.4 10.2 9.4 9 7.3 7.9; 12.09 12 12.14 11.96 13.58 14.12 14.311; 14.97 10.77 11.87 12.4 13.62 14.19 14.94]
Z = reshape(Z,numel(y),numel(x))
mesh(x,y,Z)
我是 Matlab 的新手,我想绘制一个网格。我的坐标是:
x = [30 34 38 40 44 48 50]
y = [1:5:20]
Z = [9.1 8.5 7.83 7.54 7.07 6.61 6.49 ;
14.5 8.96 8.21 7.71 7.07 6.61 6.4;
13.37 13.4 10.2 9.4 9 7.3 7.9;
12.09 12 12.14 11.96 13.58 14.12 14.311;
14.97 10.77 11.87 12.4 13.62 14.19 14.94]
我尝试在 Matlab 中绘制它时出现以下错误:
Data point coordinates have inconsistent dimension.
您确实 尺寸不一致 因为您需要 y
中的 5 个元素。您还需要一个矩阵 Z
,而不是向量。
以下应该可以帮助您入门:
y = [0:5:20]
%// reshape z in case z is a vector
z = reshape(Z,numel(y),numel(x))
figure(1)
%// mesh(x,y,z)
surf(x,y,z) % colored mesh
检查数据大小并根据需要调整整形!
一般来说,如果 X
和 Y
是向量,length(X) = n
和 length(Y) = m
,其中 `[m,n] = size(Z)v.
你的情况:
length(x)
7
length(y)
4
但是
size(Z)
1 35
所以你需要重塑Z
。
做:
x = [30 34 38 40 44 48 50]
y = [0:5:20]
Z = [9.1 8.5 7.83 7.54 7.07 6.61 6.49 ; 14.5 8.96 8.21 7.71 7.07 6.61 6.4; 13.37 13.4 10.2 9.4 9 7.3 7.9; 12.09 12 12.14 11.96 13.58 14.12 14.311; 14.97 10.77 11.87 12.4 13.62 14.19 14.94]
Z = reshape(Z,numel(y),numel(x))
mesh(x,y,Z)