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

조회 수: 3 (최근 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에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by