ploting 2 variable function

1 次查看(过去 30 天)
ram
ram 2013-10-12
回答: Yatin 2013-10-14
Hello every one
i have some problem in plotting a two variable function
i have a matrix with (m x 3)points, so the firest column represent X and the second represent Y and the last column for Z with m points in each one
I have tried using
surf(matix(:,1),matix(:,2),matix(:,3))
but it give me a message error :Z must be a matrix, not a scalar or vector.
and also try to use:
X=[matix(:,1),matix(:,2)];
Z=matix(:,3);
surf(X,Z);
it draw a surf but it seem that it ignore Z
I will be appreciated if any one can help me
  2 个评论
sixwwwwww
sixwwwwww 2013-10-12
To have surf plot you need to have Z a matrix of size m*n where m = length(X) and n = length(Y). See http://www.mathworks.com/help/matlab/ref/surf.html. But in your case you have vector. So you can use "plot3" or you create matrix Z
ram
ram 2013-10-12
realy thank you for your help it works well :)

请先登录,再进行评论。

回答(1 个)

Yatin
Yatin 2013-10-14
Hi,
The length of vector X should be the same as number of columns of Z and the length of vector Y go with number of rows of Z .
Below is a sample code snippet:
[rows, cols] = size(Z);
X = 1:cols;
Y = 1:rows;
surf(X, Y, Z);

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by