Effacer les filtres
Effacer les filtres

Find sequence of values in matrix (row wise)

6 vues (au cours des 30 derniers jours)
Manuel Schmidberger
Manuel Schmidberger le 7 Mai 2019
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

Réponse acceptée

Manuel Schmidberger
Manuel Schmidberger le 8 Mai 2019
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!

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by