フィルターのクリア

How to find two arrays of a matrix are equal? and find their location in that matrix??? for example>>> suppose we have a=[1 3 5 6 3 7] how to find which arrays are equal with each other? and find their location??? thank you very much

2 ビュー (過去 30 日間)
example:
a=[1 3 5 6 3 7]; how to find that a(2)=a(5)????

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 18 日
編集済み: Azzi Abdelmalek 2014 年 8 月 18 日
a=[1 3 5 6 3 7]
[b,ii,jj]=unique(a)
[freq,idx]=histc(a,b)
location=arrayfun(@(x) find(a==x),b,'un',0)
out=[{'a' 'frequency' 'location'};[num2cell([b',freq']) location']]
  3 件のコメント
vahid torabi
vahid torabi 2014 年 8 月 18 日
the order 'unique' makes the matrix form [1 5 2 6 2 7]>>> [1 2 5 6 7] I don't want to change the position of figures!
Image Analyst
Image Analyst 2014 年 8 月 18 日
vahid, the help has all kinds of information on all the functions. You can consult the help for questions like you just asked, and find answers like this:
[C,ia,ic] = unique(A,setOrder) and [C,ia,ic] = unique(A,'rows',setOrder) return C in a specific order. setOrder='sorted' returns the values (or rows) of C in sorted order. setOrder='stable' returns the values (or rows) of C in the same order as A. If no value is specified, the default is 'sorted'.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 8 月 18 日
There might be very very many elements that occur more than once in the array. I suggest you call histc() to get a count of all values and see which counts are 2 or greater.
a = randi(9, 1, 100)-5 % Sample data
histEdges = unique(a)
counts = histc(a, histEdges)
% Find locations
for k = 1 : length(counts)
if counts(k) >= 2
locations = find(a == histEdges(k))
end
end

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by