How to create 3D mesh surface that joins two parallel 2D data plots of similar sized X,Y sets let say a Z distance apart?

4 views (last 30 days)
Let say if I have X1 and X2 arrays of equal size which represent two different 2D plots whose Y arrays are identical and of similar size as that of X1 or X2.
The two plots represents parallel traces in 3D space that are separated from one another by Z=50. That is, plot(X1,Y) is at Z=0 and plot(X2,Y) is at Z=50 in 3D space. And I want to connect the two plots with one another through linear vector line relationship to form a 3D mesh surface.
How should I do this in MATLAB?
Thanks
  4 Comments
Walter Roberson
Walter Roberson on 12 Jul 2015
Simply connecting points of the two plots in a sequential manner does not result in a surface: it results in a set of line segments, (x1(J),y(J),0) joined to (x2(J),y(J),50)
If you want a ribbon between the two plots then you need to specify whether you want rectangular faces or triangular faces.
M. Waleed Shaukat
M. Waleed Shaukat on 12 Jul 2015
Yes, I understand it will not form a surface rather sort of it been made of several line segments.
I would like to prefer rectangular faces. However, I have tried your code and it is coming with an error saying HORZCAT ERROR. CAT ARGUMENT DIMENSIONS ARE NOT CONSISTENT after vert=[X,Y,Z] input.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jul 2015
X = [x1(:), x2(:)];
Y = [y(:), y(:)];
Z = [zeros(numel(x1),1); 50*ones(numel(x1),1)];
vert = [X, Y, Z];
N = numel(x1);
fac = [1:N-1; 2:N; N+2:2*N; N+1:2*N-1].';
patch('Faces', fac, 'Vertices', vert);
  5 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!