Equal elements between every two successive vectors equal elements between every two successive vectors in a cell array

1 回表示 (過去 30 日間)
Dear all How to find common or equal elements between every two successive vectors (not equal in length) in a cell array, e.g.
str =
Columns 1 through 5
[1x5 double] [1x37 double] [1x63 double] [1x39 double] [1x75 double]
Column 6
[1x75 double]

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 16 日
編集済み: Azzi Abdelmalek 2013 年 5 月 16 日
str={[1 2 3 4],[2 3 5 6],[5 10 20],[25 40]}
n=numel(str);
out=cell(n-1,1);
for k=1:n-1
out{k}=intersect(str{k},str{k+1})
end
  3 件のコメント
Jonathan Sullivan
Jonathan Sullivan 2013 年 5 月 16 日
Sounds like you have a script named intersect.m
You should rename your script. It's not a good idea to name custom functions and scripts the same as MATLAB's builtin functions and scripts, because name conflict issue will arise.
Another (less desirable) workaround is to use the function "builtin".
str={[1 2 3 4],[2 3 5 6],[5 10 20],[25 40]}
n=numel(str);
out=cell(n-1,1);
for k=1:n-1
out{k}=builtin('intersect',str{k},str{k+1})
end
Mohammed
Mohammed 2013 年 5 月 16 日
Thanx, I used the builtin function but I got this results
The code
vectors =
{1x5 cell} {1x37 cell} {1x63 cell} {1x39 cell}
q = length(vectors)
for qq= 1:q-1
terminals{qq} = builtin('intersect',vectors{qq}, vectors{qq+1})
end
The results
Error using builtin
Cannot find builtin function 'intersect'
Error in Area6 (line 67)
terminals{qq} = builtin('intersect',vectors{qq}, vectors{qq+1})

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by