How to create a continuos surface in 3D

Hi, I have this .mat file that is a 8950x3 matrix, the 1st column contains the x-coordinates, the 2nd one the y-coordinates and the third contains the z-coordinates. I would draw a continuos surface like the following figure
The only difference is that z is not the result of a function but is a vector. Is it possible? Thanks to all!

 Respuesta aceptada

Mischa Kim
Mischa Kim el 6 de Abr. de 2014
How about doing it from scratch?
x = -2:0.1:2;
y = -2:0.1:2;
[X,Y] = meshgrid(x,y);
Z = X.*exp(-(X - Y.^2).^2 - Y.^2);
surf(X,Y,Z)

3 comentarios

Francesco
Francesco el 6 de Abr. de 2014
But isn't it the script used to generate the example figure?
Yes it is. If you want to generate directly from the matrix from the .mat file, this should work:
M = sortrows(m,[1 2]) % m is the matrix from the .mat file
nc = numel(unique(M(:,1)));
x = reshape(M(:,1),[],nc);
y = reshape(M(:,2),[],nc);
z = reshape(M(:,3),[],nc);
surf(x,y,z)
Francesco
Francesco el 6 de Abr. de 2014
It works very well! Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

Youssef  Khmou
Youssef Khmou el 6 de Abr. de 2014
Try to use this method :
% X is the 8950*3 matrix
x=X(:,1)'*X(:,1); % 8950x8950
y=X(:,2)'*X(:,2);
z=X(:,3)'*X(:,3);
figure; surf(X,Y,Z)

3 comentarios

Francesco
Francesco el 6 de Abr. de 2014
Editada: Francesco el 6 de Abr. de 2014
I tried to do like you suggested but I have this error: Error using surf (line 75) Z must be a matrix, not a scalar or vector
Francesco
Francesco el 6 de Abr. de 2014
I noticed right now that no one among x y and z are matrices but scalar value
Youssef  Khmou
Youssef Khmou el 6 de Abr. de 2014
Editada: Youssef Khmou el 6 de Abr. de 2014
use :
X=X';
and perform the code above

Iniciar sesión para comentar.

Preguntada:

el 6 de Abr. de 2014

Comentada:

el 6 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by