Mesh Plot surface dimensions must agree
24 views (last 30 days)
Show older comments
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 Comment
Dyuman Joshi
on 22 Nov 2021
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().
Answers (1)
Star Strider
on 22 Nov 2021
The easiest solution in that instance is either to reverse the first two arguments to surf or transpose the ‘Z’ matrix.
.
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!