ploting 2 variable function

2 vues (au cours des 30 derniers jours)
ram
ram le 12 Oct 2013
Réponse apportée : Yatin le 14 Oct 2013
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 commentaires
sixwwwwww
sixwwwwww le 12 Oct 2013
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 le 12 Oct 2013
realy thank you for your help it works well :)

Connectez-vous pour commenter.

Réponses (1)

Yatin
Yatin le 14 Oct 2013
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);

Community Treasure Hunt

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

Start Hunting!

Translated by