我有一个与多维数据集8 vortex
对应的矩阵,
CubeVortex = [3 3 0;
0 3 0;
0 3 3;
3 3 3;
0 0 3;
3 0 3;
3 0 0;
0 0 0];
现在我想得到所有边缘的坐标,分为3
,例如,
如您所见,将有12x2 = 24
坐标。
写它们会有点困难。
有没有办法从CubeVortex
计算出来?
答案 0 :(得分:2)
一种方法:
Cube = [
3 3 0;
0 3 0;
0 3 3;
3 3 3;
0 0 3;
3 0 3;
3 0 0;
0 0 0];
% find edges by looking for all combinations of points on cube that
% differ by only one coordinate
sections_per_edge = 3;
weights = ((1:sections_per_edge-1) / sections_per_edge).';
edges = []; % indices into Cube
points = [];
n = size(Cube, 1);
for i = 1:n-1
pointA = Cube(i, :);
for j = i+1:n
pointB = Cube(j, :);
if nnz(pointA - pointB) == 1
edges = [edges; i, j];
% find points along edge as weighted average of point A and B
points = [points; weights * pointA + (1 - weights) * pointB];
end
end
end
% plot corners
plot3(Cube(:,1), Cube(:,2), Cube(:,3), '.r', 'markersize', 20)
hold on
% plot points along edges
plot3(points(:,1), points(:,2), points(:,3), '.b', 'markersize', 20)
% draw edges
line([Cube(edges(:,1), 1), Cube(edges(:,2), 1)].', ...
[Cube(edges(:,1), 2), Cube(edges(:,2), 2)].', ...
[Cube(edges(:,1), 3), Cube(edges(:,2), 3)].', 'color', 'k')
axis([-1,4,-1,4])
结果:
将sections_per_edge
增加到10,即可获得
答案 1 :(得分:1)
一种方法可能就是这个 -
n = 3; %// number of IDs
m = 3; %// number of columns
combs = dec2base(0:(n+1)^m-1,n+1,m)-'0' %// form repeated combinations
out = c1(sum(ismember(combs,[1 2]),2)==1,:) %// combinations for intermediate points
您可以为N-point
案例制作此通用名称,并使用此作为更高效的案例
N = 3;
[x,y,z] = ndgrid(0:N,0:N,0:N)
combs = [z(:) y(:) x(:)]
out = combs(sum(combs~=0 & combs~=N,2)==1,:)
因此,对于你的3分(0到3)的情况,你会有 -
out =
0 0 1
0 0 2
0 1 0
0 1 3
0 2 0
0 2 3
0 3 1
0 3 2
1 0 0
1 0 3
1 3 0
1 3 3
2 0 0
2 0 3
2 3 0
2 3 3
3 0 1
3 0 2
3 1 0
3 1 3
3 2 0
3 2 3
3 3 1
3 3 2
答案 2 :(得分:0)
这应该这样做:
NewVortex=[];
for i=1:3
NewVortex=[CubeVortex*i/3;NewVortex];
end
NewVortex