# Thread Subject: How to find the indexes of repeated values in a rows in a matrix?

 Subject: How to find the indexes of repeated values in a rows in a matrix? From: Paulo Guimaraes Date: 26 May, 2012 01:26:22 Message: 1 of 5 Hi all, I have a matrix like:      1 41 0 0 0 0 0 0 0      1 41 3 0 0 0 0 0 0      1 41 6 0 0 0 0 0 0      1 41 13 0 0 0 0 0 0      1 41 3 48 0 0 0 0 0      1 41 3 51 0 0 0 0 0      1 41 6 46 0 0 0 0 0      1 41 6 47 0 0 0 0 0      1 41 3 48 4 0 0 0 0      1 41 3 48 4 41 0 0 0      1 41 3 48 4 48 0 0 0      1 41 3 48 4 41 1 0 0       I want to count the repeated values per rows, so the output would be: 0 0 0 0 0 0 0 0 0 1 (41 showed up two times) 1 (48 showed up two times) 2 ( 1 and 41 showed up two times) Any clue of how I can do that? Thanks P.
 Subject: How to find the indexes of repeated values in a rows in a matrix? From: Nasser M. Abbasi Date: 26 May, 2012 01:41:15 Message: 2 of 5 On 5/25/2012 8:26 PM, Paulo Guimaraes wrote: > Hi all, > > I have a matrix like: > > 1 41 0 0 0 0 0 0 0 > 1 41 3 0 0 0 0 0 0 > 1 41 6 0 0 0 0 0 0 > 1 41 13 0 0 0 0 0 0 > 1 41 3 48 0 0 0 0 0 > 1 41 3 51 0 0 0 0 0 > 1 41 6 46 0 0 0 0 0 > 1 41 6 47 0 0 0 0 0 > 1 41 3 48 4 0 0 0 0 > 1 41 3 48 4 41 0 0 0 > 1 41 3 48 4 48 0 0 0 > 1 41 3 48 4 41 1 0 0 > > I want to count the repeated values per rows, so the output would be: > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 1 (41 showed up two times) > 1 (48 showed up two times) > 2 ( 1 and 41 showed up two times) > > Any clue of how I can do that? > > Thanks > > P. But 0 is repeated value? isn't zero a value? --Nasser
 Subject: How to find the indexes of repeated values in a rows in a matrix? From: Nasser M. Abbasi Date: 26 May, 2012 01:59:13 Message: 3 of 5 On 5/25/2012 8:26 PM, Paulo Guimaraes wrote: > Hi all, > > I have a matrix like: > > 1 41 0 0 0 0 0 0 0 > 1 41 3 0 0 0 0 0 0 > 1 41 6 0 0 0 0 0 0 > 1 41 13 0 0 0 0 0 0 > 1 41 3 48 0 0 0 0 0 > 1 41 3 51 0 0 0 0 0 > 1 41 6 46 0 0 0 0 0 > 1 41 6 47 0 0 0 0 0 > 1 41 3 48 4 0 0 0 0 > 1 41 3 48 4 41 0 0 0 > 1 41 3 48 4 48 0 0 0 > 1 41 3 48 4 41 1 0 0 > > I want to count the repeated values per rows, so the output would be: > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 1 (41 showed up two times) > 1 (48 showed up two times) > 2 ( 1 and 41 showed up two times) > > Any clue of how I can do that? > > Thanks > > P. This assumes 0 is not part of the logic for repeated as you show above. Hence I replaced 0 by nan to get this to work: --------------------------------- B = A; B(A==0) = nan; r = zeros(size(B,1),1); for i = 1:length(r)       u = unique(B(i,:));       n = hist(B(i,:),u);       r(i) = length(n(n>1)); end ---------------------------------- EDU>> r r =       0       0       0       0       0       0       0       0       0       1       1       2 --Nasser
 Subject: How to find the indexes of repeated values in a rows in a matrix? From: Paulo Guimaraes Date: 26 May, 2012 02:59:41 Message: 4 of 5 Thanks! Yes, it was just for nonzero values. Thank you very much. "Paulo Guimaraes" wrote in message ... > Hi all, > > I have a matrix like: > > 1 41 0 0 0 0 0 0 0 > 1 41 3 0 0 0 0 0 0 > 1 41 6 0 0 0 0 0 0 > 1 41 13 0 0 0 0 0 0 > 1 41 3 48 0 0 0 0 0 > 1 41 3 51 0 0 0 0 0 > 1 41 6 46 0 0 0 0 0 > 1 41 6 47 0 0 0 0 0 > 1 41 3 48 4 0 0 0 0 > 1 41 3 48 4 41 0 0 0 > 1 41 3 48 4 48 0 0 0 > 1 41 3 48 4 41 1 0 0 > > I want to count the repeated values per rows, so the output would be: > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 1 (41 showed up two times) > 1 (48 showed up two times) > 2 ( 1 and 41 showed up two times) > > Any clue of how I can do that? > > Thanks > > P.
 Subject: How to find the indexes of repeated values in a rows in a matrix? From: Bruno Luong Date: 26 May, 2012 08:10:41 Message: 5 of 5 "Paulo Guimaraes" wrote in message ... > Hi all, > > I have a matrix like: > > 1 41 0 0 0 0 0 0 0 > 1 41 3 0 0 0 0 0 0 > 1 41 6 0 0 0 0 0 0 > 1 41 13 0 0 0 0 0 0 > 1 41 3 48 0 0 0 0 0 > 1 41 3 51 0 0 0 0 0 > 1 41 6 46 0 0 0 0 0 > 1 41 6 47 0 0 0 0 0 > 1 41 3 48 4 0 0 0 0 > 1 41 3 48 4 41 0 0 0 > 1 41 3 48 4 48 0 0 0 > 1 41 3 48 4 41 1 0 0 > > I want to count the repeated values per rows, so the output would be: > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 0 > 1 (41 showed up two times) > 1 (48 showed up two times) > 2 ( 1 and 41 showed up two times) > > Any clue of how I can do that? Assuming "valid" elements of A are > 0: sum(diff(diff([false(size(A,1),1) sort(A,2)],1,2)<=0,1,2)==1,2) % Bruno

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.