필터 지우기
필터 지우기

How to find repeated elements , numbers and corresponding values?

조회 수: 1 (최근 30일)
Cladio Andrea
Cladio Andrea 2015년 3월 2일
답변: Andrei Bobrov 2015년 3월 2일
Hello everyone, i have matrices like that:
1701595 1000
1704973 1000
1704973 1000
1713813 1000
1713812 1000
1713813 1000
1718216 1000
1718217 1000
1721276 1000
1730543 1000
1730544 1000
1733979 1000
1733978 1000
1754675 1000
1755167 1000
1764620 1000
1767147 1000
1767147 1000
1767146 1000
1768028 1000
1778080 1000
1792257 1000
1792257 1000
1803714 1000
1815437 1000
1820059 1000
1826840 1000
1828145 1000
as you see, there are some same elements in the first row, what i want is , as a third row is that if an element is repeated in the first row, delete the first one(s) row, just keep the last row and write how many times that element is repeated, and as a fourth row, lets say if it is repeated four time than the fourth column will be 4000 for this element, please can you give me an idea about how to do that?
  댓글 수: 1
Adam
Adam 2015년 3월 2일
You seem to be mixing up rows and columns in your question in numerous places, or I'm just misunderstanding what you want.
I assume you means there are some same elements in the first column and that you wish to put 4000 in the second column for a row that represents the 4th row with an identical value in the 1st column?

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 3월 2일
a = [1701595 1000
1704973 1000
1704973 1000
1713813 1000
1713812 1000
1713813 1000
1718216 1000
1718217 1000
1721276 1000
1730543 1000
1730544 1000
1733979 1000
1733978 1000
1754675 1000
1755167 1000
1764620 1000
1767147 1000
1767147 1000
1767146 1000
1768028 1000
1778080 1000
1792257 1000
1792257 1000
1803714 1000
1815437 1000
1820059 1000
1826840 1000
1828145 1000];
[~,b1,c1] = unique(a(:,1),'stable');
out = [a(b1,:) accumarray(c1,1)];

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by