Hello, Quick question : is it possible to make surfc works with vectors ? I have 4 vectors (x,y,z & c for the color) of the same length (1 point per quadruple xyzc ) but I don't understand how to turn them into matrix as surfc asks me. The xyz points are uniformly spaced. Any idea ?

 Réponse acceptée

Grzegorz Knor
Grzegorz Knor le 28 Sep 2011

0 votes

Use reshape function, or interpolate the data:

5 commentaires

Kevin
Kevin le 28 Sep 2011
I don't really understand how "reshape" can help me here. What do you mean ?
And, since my points are already uniformly spaced, I don't want to do an interpolation.
Grzegorz Knor
Grzegorz Knor le 28 Sep 2011
I don't know how you create your data, but look at example:
% create an example surface plot:
[X,Y,Z] = peaks(30);
surfc(X,Y,Z,abs(Z))
% convert to single columns:
x = X(:);
y = Y(:);
z = Z(:);
c = abs(z);
% surfc(x,y,z,c) <- error
% create a surface plot using reshape function:
figure
surfc(reshape(x,30,30),reshape(y,30,30),reshape(z,30,30),reshape(c,30,30))
Kevin
Kevin le 28 Sep 2011
Ah nice ! But that works only if you can do a square matrix. And of course, well, I can't ! :)
Grzegorz Knor
Grzegorz Knor le 28 Sep 2011
Matrices can be any size, but you need to know it.
[x,y] = meshgrid(-2:.1:2, -2:.2:2);
x = x(:);
y = y(:);
z = x.*exp(-x.^2 - y.^2);
c = abs(z);
surfc(reshape(x,21,41),reshape(y,21,41),reshape(z,21,41),reshape(c,21,41))
Kevin
Kevin le 28 Sep 2011
It works thanks but I had to add a value because the lenght of my data was a prime number...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Preprocessing dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by