フィルターのクリア

Comparing vectors and determining unique values?

1 回表示 (過去 30 日間)
Jonathan Wong
Jonathan Wong 2015 年 5 月 16 日
回答済み: Andrei Bobrov 2015 年 5 月 16 日
Let's say I have a 3x3 cell array. In each cell is a vector. For a given cell, how do I determine the unique number the vector of that cell has that no others in the cell array has.
Or in a simpler case, consider a 2x2 cell array, C.
C=
[1 0 3 4] [0 2 3 0]
[0 2 0 4] [0 2 3 4]
How can I take the vector in C{1,1} and compare it to the other vectors and pull out the number "1" which is unique among the vectors in the cell array.

回答 (2 件)

per isakson
per isakson 2015 年 5 月 16 日
編集済み: per isakson 2015 年 5 月 16 日
Try this script
cac = {
[1 0 3 4] [0 2 3 0]
[0 2 0 4] [0 2 3 4] };
%
ixa = ( 1 : numel(cac) ); % linear indices of all vectors
ix1 = sub2ind( size(cac), 1, 1 ); % linear index of selected vector
the_other_vectors = cat( 2, cac{setdiff(ixa,ix1)} );
%
setdiff( cac{ix1}, the_other_vectors )
it returns
ans =
1

Andrei Bobrov
Andrei Bobrov 2015 年 5 月 16 日
c = C{1}
for ii = 2:numel(C)
c = setdiff(c,C{ii});
end

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by