2016-08-10 1 views
-3

에서 제거 나는고급 검색 및 특수 매트릭스

X= [2 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 250; 
    3 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 250; 
    2 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 250; 
    3 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 250; 
    4 0 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 250; 
    3 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 250; 
    2 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 1 250; 
    4 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 250; 
    3 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 250; 
    3 1 1 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 400] 

내가이 행렬에 세 가지 다른 시퀀스 작업을 수행하기 위해 필요한이 매트릭스를 가지고 다음과 같은 순서 1 1 0이 매트릭스

1 검색 0 0을 만들고이 특성을 가진 행을 새 행렬 (행 1과 같음)에 씁니다.

2- 첫 번째 단계에서 생성 된 행렬을 사용하여 동일한 숫자 (행 1,3,7과 같은 번호)를 가진 행으로 제거하지만 동시에 한 행만 유지하십시오 각 행 (1,3,7 행의 경우 행 1을 유지하고 다른 행을 제거).

3 두 번째 단계에서 생성되는 행렬을 사용하고이 행렬에서 다음과 같은 순서 (행 8과 같은)가있는 행을 제거하고이 행렬의 다른 행을 새 행렬에 넣습니다. 의

+0

가능한 복제 [매트릭스를 생성이 특별한 charactristics] (http://stackoverflow.com/questions/39486469/generate-matrix-have-special-charactristics) –

답변

1
%Step-1 
% Converting the matrix into a string, appending a semi-colon for similarity and removing the brackets from the string 
req=mat2str(X);  req(end)=';'  ; req=req(2:end); 
% Searching the sequence: 1 1 0 0 0 
sp1=strfind(req, '1 1 0 0 0'); 
% Storing those rows of X in req matrix which contain the sequence 
req=X(unique(ceil([sp1]/(size(req,2)/size(X,1)))),:); 


%Step-2 
req= unique(req,'rows'); 

%Step-3 
% Converting the matrix into a string, appending a semi-colon for similarity and removing the brackets from the string 
reqtemp=mat2str(req); reqtemp(end)=';' ; reqtemp=reqtemp(2:end); 
% Searching the sequence: 1 1 1 
sp1=strfind(reqtemp, '1 1 1'); 
% Removing those rows which contain the sequence 
req(unique(ceil([sp1]/(size(reqtemp,2)/size(req,1)))),:)=[];