How to remove array elements that are elements of a different array
1 回表示 (過去 30 日間)
古いコメントを表示
relations is a cell array of arrays. max_commons is an array.
I would like to go over each cell of relations and remove the elements that are in max_commons from its array. I have no idea how to do it succintly.
I tried such a syntax:
for k = 1:num
relations{k} = relations{k}(relations{k}~=max_commons);
end
as in relations{k} becomes relations{k} but without the elements in relations of{k} that were also in max_commons.
However, this gives a bunch of errors. Do you know how to achieve the above task?
0 件のコメント
回答 (1 件)
James Tursa
2016 年 10 月 11 日
編集済み: James Tursa
2016 年 10 月 11 日
Assuming relations{k} is some arbitrarily sized array and max_commons is some arbitrarily sized vector:
relations{k} = relations{k}(~ismember(relations{k},max_commons));
Or to do it all at once without the explicit loop:
relations = cellfun(@(x)x(~ismember(x,max_commons)),relations,'uni',false);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!