Reputation: 355
I'm new to Matlab and I want to plot a mesh. My coordinates are:
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]
Ehen I tried to plot it in Matlab it gives following error:
Data point coordinates have inconsistent dimension.
Upvotes: 2
Views: 891
Reputation: 25232
You have indeed inconsistent dimensions as you need 5 elements in y
. Also you need a matrix Z
, not a vector.
The following should get you starting:
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
Check the data sizes and adjust the reshaping according to your needs!
Upvotes: 2
Reputation: 33147
In general, if X
and Y
are vectors, length(X) = n
and length(Y) = m
, where `[m,n] = size(Z)v.
In your case:
length(x)
7
length(y)
4
but
size(Z)
1 35
So you need to reshape the Z
.
Do:
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)
Upvotes: 2