How to delete repeating column or duplicate column in MATLAB? of type Double

조회 수: 70 (최근 30일)
Hi,
How to delete the repeating or duplicate columns in matrix, is there any function in MATLAB?, for example in the input array row 2 are basically the occurance or row 1 values, so i am basically counting how many times that partiuclar value in row 1 has appeared in row 1.
Thanks in Advance
input array:
2 2 5 1 1 3 4 3 4
2 2 1 2 2 2 2 2 2
output array:
2 5 1 3 4
2 1 2 2 2
or more precise
1 2 3 4 5
2 2 2 2 1
  댓글 수: 2
the cyclist
the cyclist 2019년 5월 17일
Is the "more precise" one like that because it is sorted by the top row?
Is there any special way to handle repeated values in the top row?
raghavendra kandukuri
raghavendra kandukuri 2019년 5월 17일
The More precise is the sorted order of ouput array

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

채택된 답변

Matt J
Matt J 2019년 5월 17일
편집: Matt J 2019년 5월 17일
output_array=unique(input_array.','rows').'
  댓글 수: 5
omran alshalabi
omran alshalabi 2022년 8월 28일
편집: dpb 2022년 8월 28일
how to code to delet repeating value in a row like this:
from
a = [1 2 2 4 4 2 2 1 1 4 4 ]
become
b = [1 2 4 2 1 4]
dpb
dpb 2022년 8월 28일
This really should be a new Q? because to Answer here isn't responsive to the original -- but...
a = [1 2 2 4 4 2 2 1 1 4 4 ] ;
ix=find(diff(a));
a([1 ix+1])
ans = 1×6
1 2 4 2 1 4

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

추가 답변 (1개)

dpb
dpb 2019년 5월 17일
편집: dpb 2019년 5월 17일
>> uA=unique(A);
>> B=[uA;histc(A,uA)]
B =
1 2 3 4 5
2 2 2 2 1
>>
ADDENDUM: Above works with only the first row and computes the counts on the presumption they had to have been obtained somewhere before to have been posted...

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by