Hi, I've solved it. What I did is the following:
points 1, 2, 3 and 4 are points from the top surface and 5,6,7 and 8 are points from the bottom surface. I need two triangles to connect 4 points together, which means 2 rows in the connectivity matrix. I created the ConnectSurfaces function, which generates a connectivity matrix given a certain number of points, which will be the nº of rows in the vector with coordinates:
% Delaunay constraints for 2D top and bottom surfaces
nump = numel(app.pointsPinion(:,1));
C = [(1:(nump-1))' (2:nump)'; nump 1];
% Triangulation
dt = delaunayTriangulation(app.pointsPinion(:,1),app.pointsPinion(:,2),C);
% For filtering triangles outside profile defined by the original points
io = isInterior(dt);
figure
h(1) = trisurf(dt.ConnectivityList(io,:),app.pointsPinion(:,1),app.pointsPinion(:,2),app.pointsPinion(:,3),'FaceColor','r','EdgeColor','k');
hold on
h(2) = trisurf(dt.ConnectivityList(io,:),app.pointsPinion(:,1),app.pointsPinion(:,2),app.pointsPinion(:,3)+app.optiTrans.b,'FaceColor','r','EdgeColor','k');
n_points = size(app.pointsPinion,1);
ConMat = ConnectSurfaces(n_points);
trisurf(ConMat,[app.pointsPinion(:,1);app.pointsPinion(:,1)],[app.pointsPinion(:,2);app.pointsPinion(:,2)],[app.pointsPinion(:,3);app.pointsPinion(:,3)+app.optiTrans.b],'FaceColor','r','EdgeColor','k')
axis tight
pbaspect([1 1 1])
function ConnectivityMatrix = ConnectSurfaces(n_points)
for j = 1:1:n_points-1
k = 2*j;
ConnectivityMatrix(k-1,1) = j;
ConnectivityMatrix(k-1,2) = j+1;
ConnectivityMatrix(k-1,3) = j+n_points;
ConnectivityMatrix(k,1) = j+n_points;
ConnectivityMatrix(k,2) = j+n_points+1;
ConnectivityMatrix(k,3) = j+1;
end
% The following is for connecting the last pair of points with the first to get a closed donut-like surface
ConnectivityMatrix = [ConnectivityMatrix;[n_points 1 n_points*2];[n_points*2 n_points+1 1]];
end
The above solution yields the following result, which is what I was looking for: