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

120 ビュー (過去 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 件のコメント
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 件のコメント
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...

カテゴリ

Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by