Mesh Plot surface dimensions must agree

조회 수: 35 (최근 30일)
Heath Carignan
Heath Carignan 2021년 11월 22일
답변: Star Strider 2021년 11월 22일
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
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
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.
.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by