From: Jack on 28 Jun 2010 19:06 Hi, I have a matrix consisting of a large number of rows. I need to know which rows has been repeated exactly the same more than once and how many times they have been repeated. For Example if A= [ 1 2 3 ; 4 3 5; 1 2 3; 1 2 3; 4 3 5; 5 2 1; 3 2 1; 3 5 1] then I should get something like the following: 1 2 3 : 3 times 4 3 5: 2 times I wonder if there is an easy way to do it? many thanks
From: Matt Fig on 28 Jun 2010 19:33 How about a hard way? % Data A= [ 1 2 3 ; 4 3 5; 1 2 3; 1 2 3; 4 3 5; 5 2 1; 3 2 1; 3 5 1] % Engine B = sortrows(A); S = [1;any(diff(B),2)]; [L,S] = regexp(sprintf('%i',S'),'1(0)+','start','end'); repeated_rows = B(S,:) % Repeated Rows. repeat_count = (S-L+1)' % How often each repeated row appears.
From: Jack on 30 Jun 2010 18:06 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i0bbg4$l1k$1(a)fred.mathworks.com>... > How about a hard way? > > % Data > A= [ 1 2 3 ; 4 3 5; 1 2 3; 1 2 3; 4 3 5; 5 2 1; 3 2 1; 3 5 1] > > > % Engine > B = sortrows(A); > S = [1;any(diff(B),2)]; > [L,S] = regexp(sprintf('%i',S'),'1(0)+','start','end'); > repeated_rows = B(S,:) % Repeated Rows. > repeat_count = (S-L+1)' % How often each repeated row appears. My Dear; Thanks alot for your response; I found it by coincedence. I did not receive an email "as usual" letting me know someone has responded... this is weired. I will go and check the code right now. Many thanks
From: sscnekro on 30 Jun 2010 21:13 > Thanks alot for your response; I found it by coincedence. I did not receive an email "as usual" letting me know someone has responded... this is weired Now I start to understand why some guys don't know about the help they really receive. They wait for e-mail instead of coming to the page. And it's also true that there were two or three cases when I e-mailed an alert on my nwsgr. reply (when the person was a first poster and seemed too desperate).
From: Jack on 1 Jul 2010 00:33 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <i0bbg4$l1k$1(a)fred.mathworks.com>... > How about a hard way? > > % Data > A= [ 1 2 3 ; 4 3 5; 1 2 3; 1 2 3; 4 3 5; 5 2 1; 3 2 1; 3 5 1] > > > % Engine > B = sortrows(A); > S = [1;any(diff(B),2)]; > [L,S] = regexp(sprintf('%i',S'),'1(0)+','start','end'); > repeated_rows = B(S,:) % Repeated Rows. > repeat_count = (S-L+1)' % How often each repeated row appears. Dear Matt; Thanks a lot, this works well :) but it is really a hard way at least for me, I had to go to the help menu many times!! but how could I make change to the code if I want to list all the rows ( not only those repeated more than once)? Best Regards
|
Next
|
Last
Pages: 1 2 Prev: Obtaining the pixel values of two black points in an image! Next: Selecting Files in a folder |