If I'm right, you're looking for somthing like the following solution. The idea is taken from Amro's answer here.
Idea
The code first creates vectors with start and stop vertices. It then creates a matrix holding lines with the start vertex, stop vertex and inserts a nan
line. Then it uses patch
to plot a surface and makes the face invisible. Note, that for reeeaally many vertices, this "wastes" some memory for the nans
but the patch command is quite fast, as it creates only one object.
Code
% Sample coordinates
coord = [ 1 -1.3 -1;...
-1 -1.3 -1;...
-1 -1.3 1;...
1 -1.3 1;...
1 1.3 -1;...
-1 1.3 -1;...
-1 1.3 1;...
1 1.3 1;...
-1.3 1 -1;...
-1.3 -1 -1;...
-1.3 -1 1;...
-1.3 1 1;...
1.3 1 -1;...
1.3 -1 -1;...
1.3 -1 1;...
1.3 1 1;...
1 -1 -1.3;...
-1 -1 -1.3;...
-1 1 -1.3;...
1 1 -1.3;...
1 -1 1.3;...
-1 -1 1.3;...
-1 1 1.3;...
1 1 1.3];
nlines = size(coord, 1);
% Vectors for vertices
X = zeros(2, nlines);
Y = zeros(2, nlines);
Z = zeros(2, nlines);
C = zeros(1, nlines);
% One iteration per vertex
for ii = 1:nlines
% Here comes the edge back to the first vertex
if mod(ii,4) == 0
X(1, ii) = coord(ii, 1);
Y(1, ii) = coord(ii, 2);
Z(1, ii) = coord(ii, 3);
X(2, ii) = coord(ii-3, 1);
Y(2, ii) = coord(ii-3, 2);
Z(2, ii) = coord(ii-3, 3);
% Here come all other edges
else
X(1, ii) = coord(ii, 1);
Y(1, ii) = coord(ii, 2);
Z(1, ii) = coord(ii, 3);
X(2, ii) = coord(ii+1, 1);
Y(2, ii) = coord(ii+1, 2);
Z(2, ii) = coord(ii+1, 3);
end
% One color for each rectangle
C(ii) = floor((ii-1)/4);
end
% Insert nans between lines
X(end+1, :) = nan;
Xf = X(:);
Y(end+1, :) = nan;
Yf = Y(:);
Z(end+1, :) = nan;
Zf = Z(:);
% Setup patch matrix
p = [Xf, Yf, Zf];
% Prepare color matrix
r = repmat(C.', 1, 3)';
clr = r(:);
% Make a figure
f = figure;
% Plot patch
surface(p(:,[1 1]), p(:,[2 2]), p(:,[3 3]), [clr clr], ...
'EdgeColor', 'flat', ....
'FaceColor', 'None')
grid on
view([55, 36]);
xlabel('X')
ylabel('Y')
zlabel('Z')
Plot
