필터 지우기
필터 지우기

Find sequence of values in matrix (row wise)

조회 수: 6 (최근 30일)
Manuel Schmidberger
Manuel Schmidberger 2019년 5월 7일
답변: Manuel Schmidberger 2019년 5월 8일
Hi,
I have problem and not sure how to solve this in a good way. I have a matrix RCX with m rows of n cartesian coordinates.
RCX= [219, 232, 241, 261, 0, 0, 0, 0;
446, 455, 464, 0, 0, 0, 0, 0;
760, 767, 775, 0, 0, 0, 0, 0;
232, 241, 261, 0, 0, 0, 0, 0;
264, 275, 282, 0, 0, 0, 0, 0;
259, 268, 276, 0, 0, 0, 0, 0;
295, 309, 321, 335, 345, 351, 363, 381;
309, 321, 335, 345, 351, 363, 381, 0;]
Now I wanna find alle duplicate nonzero sequenzes in this matrix and filter them out if they are shorter as another existing. For example RCX(4,1:3) = RCX(1,2:4) and RCX(8,1:7)=RCX(7,2:8).
At the end I wanna delete the shorter sequences if they are fully covered by another and longer sequence. So RCX(4,:) and RCX(8,:) should be deleted.
(Matlab release 2015a)
Thanks a lot!
~ Kind regards,
Manuel

채택된 답변

Manuel Schmidberger
Manuel Schmidberger 2019년 5월 8일
I solved the problem this way so far:
% Get cell array with non zero values:
rsm=sort(RCX');
[~,J,values]=find(rsm);
u=unique([J,values],'rows');
N=size(u,1);
tmp=diff([0;find(diff(u(:,1)));N]);
out1=mat2cell(u(:,2),tmp);
RCXcell=out1;
clear out1 rsm rsm0 u N tmp
% find complete rows as sequence in other rows
delVec=zeros(size(RCX,1),1);
for i=1:size(RCX,1)
for j=1:size(RCX,1)
Index=strfind(RCX(j,:),RCXcell{i}');
if ~isempty(Index) && j~=i
delVec(i)=1;
end
end
end
k=find(delVec);
RCX(k,:)=[];
It works for my purpose because the fields are not that big, but still not happy using two loops,
Anyway still not found an other more advanced solution. Which could be faster and usable for big fields
Best regards!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by