how to select specific values of nx3 array where the third dimension contains values in range of 1 to 11 of the 3rd dimension?

1 次查看(过去 30 天)
Hi, i was having a struct contains 2 fields of faces and vertices, now i need to extract the vertices from the struct where the z axis in the range of 1:11 then delete the faces that not related to them however, i tried to convert the struct into cell array, then i split the vertices in separate nx3 array to work on it. now what is the expression i need to complete with in order to extract only values from 1 to 11 of the 3rd dimension from this nx3 array? this is my trials :
C2 = struct2cell(splitpatch2);
f2=C2{1,1};
v2=C2{2,1};
Ver2=v2(:,:,1:11)
the last line gives me a "Index exceeds matrix dimensions." error.

采纳的回答

KSSV
KSSV 2018-10-3
编辑:KSSV 2018-10-4
S = load('splitpatch2.mat') ;
f = S.splitpatch2.faces ;
v = S.splitpatch2.vertices ;
nnode = length(v) ;
idx = v(:,3)>=1 & v(:,3)<=11 ;
iwant_nodes = find(idx) ;
iwant = v(idx,:) ;
% Plot extracted mesh alone
v_iwant = NaN(nnode,3) ;
v_iwant(idx,:) = v(idx,:) ;
trisurf(f,v_iwant(:,1),v_iwant(:,2),v_iwant(:,3)) ;
% Get faces which has iwant
idx1 = find(ismember(f(:,1),iwant_nodes)) ;
idx2 = find(ismember(f(:,2),iwant_nodes)) ;
idx3 = find(ismember(f(:,3),iwant_nodes)) ;
idx123 = [idx1 ; idx2 ; idx3] ;
iwant_faces = f(unique(idx123),:) ;
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by