Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在matlab中绘制多个三维矩形_Matlab_For Loop_Plot_3d - Fatal编程技术网

在matlab中绘制多个三维矩形

在matlab中绘制多个三维矩形,matlab,for-loop,plot,3d,Matlab,For Loop,Plot,3d,我有一个大小为400x3的数据点数组(400个点带有x、y、z坐标)。 每组4个连续点表示矩形的角, 所以有100个矩形(有限平面) 我想在3D中绘制所有100个矩形,但我对matlab非常陌生 到目前为止,我能够绘制一个矩形: % A sample rectangle pointB=[16.1445 20.0025 1.64238]; pointC=[21.7378 29.1242 1.64238]; pointD=[30.8595 23.5309 -1.64238]; pointE=[25.

我有一个大小为400x3的数据点数组(400个点带有x、y、z坐标)。 每组4个连续点表示矩形的角, 所以有100个矩形(有限平面)

我想在3D中绘制所有100个矩形,但我对matlab非常陌生

到目前为止,我能够绘制一个矩形:

% A sample rectangle
pointB=[16.1445 20.0025 1.64238];
pointC=[21.7378 29.1242 1.64238];
pointD=[30.8595 23.5309 -1.64238];
pointE=[25.2662 14.4092 -1.64238];

% Plot in 3D
points=[pointB' pointC' pointD' pointE'];
fill3(points(1,:),points(2,:),points(3,:),'r')
grid on
alpha(0.3)
那么,我该如何对其余的矩形重复这一点。。救命啊

这应该可以

% Load sample points
pointB=[16.1445 20.0025 1.64238];
pointC=[21.7378 29.1242 1.64238];
pointD=[30.8595 23.5309 -1.64238];
pointE=[25.2662 14.4092 -1.64238];

% The dimensions of points are now BCDE(4) x XYZ(3) x shapes(1)
points = [pointB; pointC; pointD; pointE];
size(points)
% Permute the dimensions for fill3 BCDE(4) x shapes(1) x XYZ(3)
points = permute(points, [1 3 2]);
size(points)

% Make some simulated rectangles (you would load these from a file)
% We will add to XYZ, making copies along the 2nd (shapes) dimension
% offset is 1 x shapes(11) x XYZ(3)
offset = permute([0:10:100; 0:10:100; 0:1:10], [3 2 1]);
% The dimensions of points are now BCDE(4) x shapes(11) x XYZ(3)
points = bsxfun(@plus, points, offset);
size(points)

% Extract X,Y,Z, so each is BCDE(4) x shapes(11)
X = points(:,:,1);
Y = points(:,:,2);
Z = points(:,:,3);

% Plot
fill3(X, Y, Z, 'r');
grid on;
alpha(0.3);

这不是和你上一个问题一样吗?呵呵。不,数字不同。