Mesh Plot surface dimensions must agree
26 次查看(过去 30 天)
显示 更早的评论
Hello,
I am plotting a map of a lake and its depth level for a class of mine.
I have compiled all my data intro a matrix and I am trying to apply it to a mesh plot using the mesh(...) function. However when I run my code I keep getting a "Data Dimensions must Agree" error even when I check that the x and y values that I set match the length and height of the matrix that I will be using as my z value.
Could I get some help in finding out what I'm doing wrong?
Thanks!
%--------------------------------------------------------------------------
% The map containing the data was broken into squares containing each given
% data point or approximate value. The plot is 41 x 42 squares
%--------------------------------------------------------------------------
x = 0:1:41;
y = 0:1:42;
z = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -30 0 0 0 0 0 0 -60 -70 -50 -30 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10 -40 -40 -30 -30 -20 0 -50 -60 -60 -20 -20 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -30 -30 -30 0 0 0 -50 -60 -60 0 0 0 ;
0 0 0 -20 0 0 0 0 0 0 0 0 -10 -10 0 -30 -20 -10 -10 -30 -30 0 0 -30 0 -50 -50 -50 0 0 0 ;
0 0 0 -30 -30 0 0 0 0 0 0 -40 0 -10 -30 -10 -10 0 0 -20 -30 0 0 -30 -50 -50 -50 0 0 0 0 ;
0 0 -20 -40 -40 -30 0 0 -30 -30 -40 -40 0 0 -10 0 0 0 0 0 -20 -50 -30 -40 -50 -60 -50 0 0 0 0 ;
0 0 0 -20 -40 -40 0 0 -40 -40 -50 0 0 0 0 0 0 -10 0 0 -40 -60 -50 -30 -50 -60 -50 0 0 0 0 ;
0 0 -20 0 -30 -50 -40 0 -30 -50 -40 -40 0 0 0 -10 -30 -30 -60 -40 -50 -50 -40 -30 -20 0 -30 0 0 0 0 ;
0 0 -20 0 -30 -50 -40 -40 -40 -60 -50 -50 -30 -30 -30 -30 -30 -60 -70 -70 -40 -40 0 0 -20 -10 -20 0 0 0 0 ;
0 0 0 -20 -30 -40 -50 -50 -70 -90 -90 -50 -30 -10 -40 -40 -40 -50 -60 -50 -30 -30 0 0 -10 0 0 0 0 0 0 ;
0 0 0 -20 -30 -40 -50 -70 -70 -80 -90 -80 -70 -50 -50 -60 -60 -70 -80 -70 -30 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 -20 -30 -40 -50 -60 -70 -70 -80 -70 -60 -30 -40 -30 -50 -40 -70 -60 -40 0 0 0 0 0 0 0 0 0 0 ;
-10 -10 0 -20 -30 -30 -40 -60 -70 -60 -50 -60 -60 -40 -40 -10 -20 -40 -60 -40 -30 0 0 0 0 0 0 0 0 0 0 ;
-10 0 -30 -30 -30 -40 -50 -50 -60 -50 -40 -50 -40 -40 -40 -30 -20 -60 -60 -30 0 0 0 0 0 0 0 0 0 0 0 ;
0 -20 -30 0 -30 -20 -40 -40 -50 -40 -40 -30 -30 -30 -30 -30 -10 -10 -40 -40 -30 0 0 0 0 0 0 0 0 0 0 ;
-20 -30 -30 0 -30 -10 0 -30 -40 -30 -10 -10 -20 -20 0 -30 -10 -10 -40 -40 -30 0 0 0 0 0 0 0 0 0 0 ;
0 0 -30 -40 -30 -10 -20 0 0 -10 0 0 -10 0 0 -40 -30 -30 -40 -40 -30 -20 0 0 0 0 0 0 0 0 0 ;
0 0 0 -30 -30 -30 0 0 0 -20 0 0 0 0 0 -30 -30 -20 -20 -40 -30 -20 -10 0 0 0 0 0 0 0 0 ;
0 0 0 0 -10 -20 -20 -30 -30 -30 -20 -20 -20 -30 0 -10 -20 -30 -20 -30 -40 -20 -10 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 -30 -40 -20 -30 0 -40 -30 -30 -30 -20 -30 -40 0 0 -30 -30 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 -30 -20 -20 -30 -40 -40 -40 -30 -10 -20 -50 -50 0 0 0 -30 -20 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 -30 -30 -30 -30 -30 -30 -40 -30 0 -30 -40 -40 -10 0 0 0 -30 0 0 0 0 0 0 0 0 ;
0 0 0 0 -10 -20 -20 -20 -30 0 0 0 -40 -30 0 -30 -40 -40 -20 -10 0 0 0 -30 -30 0 0 0 0 0 0 ;
0 0 -10 -20 -10 -40 -50 -40 -30 0 -10 -10 -30 -30 -10 -20 -40 -30 -30 -20 -10 0 0 0 -30 -20 0 0 0 0 0 ;
-20 -10 -30 -20 -30 -40 -20 -30 -30 -30 0 0 -30 -30 0 0 -40 -40 -20 0 0 0 0 0 -20 -20 -20 -20 0 0 0 ;
-30 -20 -30 -20 -30 -30 -30 -30 -30 -30 -20 0 -30 -20 0 0 -20 -40 -40 -10 0 0 0 0 -30 -30 0 0 0 0 0 ;
-30 -30 -30 -30 -30 -20 -10 -30 -20 -30 -20 -10 -30 -20 0 0 0 -20 -30 -40 -30 -20 -20 -10 0 0 0 0 0 0 0 ;
-30 0 0 -10 -20 -20 -10 -10 -30 -30 -10 -20 -20 -30 -20 0 0 0 -20 -20 -20 -10 -10 -10 0 0 0 0 0 0 0 ;
0 0 0 0 -10 -20 -20 -30 -30 -30 0 0 -10 -20 -30 -20 0 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 ;
0 0 0 0 0 -10 -20 -30 -30 -30 -20 0 0 0 -30 -30 0 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 -10 -30 -20 -30 0 0 0 0 -10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 -20 -20 -20 -30 0 0 0 -10 -20 -20 -20 -20 0 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 -10 0 0 -30 -30 0 0 0 -20 -30 -30 -30 -10 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 -10 -30 -20 0 -10 -20 -30 -30 -30 0 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 -10 -30 -30 -10 0 0 -20 -30 -20 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 -10 -10 -10 0 0 0 -30 -20 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 -20 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -20 -10 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10 -10 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10 -10 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -10 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ;];
mesh(x,y,z)
1 个评论
Dyuman Joshi
2021-11-22
The error you are getting is pretty straight-forward. The size of all input arguments should be same.
size(x) = 1x41, size(y) = 1x42 and size(z) = 41x42. All sizes should be same for mesh().
回答(1 个)
Star Strider
2021-11-22
The easiest solution in that instance is either to reverse the first two arguments to surf or transpose the ‘Z’ matrix.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!