add element to cell

2 ビュー (過去 30 日間)
NA
NA 2018 年 10 月 15 日
編集済み: Stephen23 2018 年 10 月 15 日
I have E and M
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13;
7 8;7 9;9 10;9 14;10 11;12 13;13 14]
M = {[1,2,5],[2,4,5],[2,3,4],[4,7,9],[6,12,13],[6,9,10,11,13,14],[4,5,6,9,10,11]};
As you can see all element in E is used in M except element 8. I want to write a code that if some element is not used in M, add that row of matrix E to the as a new cell in M. So I want this result
new_M== {[1,2,5],[2,4,5],[2,3,4],[4,7,9],[6,12,13],[6,9,10,11,13,14],[4,5,6,9,10,11],[7,8]};

採用された回答

Stephen23
Stephen23 2018 年 10 月 15 日
編集済み: Stephen23 2018 年 10 月 15 日
>> idx = ~all(ismember(E,[M{:}]),2);
>> M = [M(:);num2cell(E(idx,:),2)];
>> M{:}
ans =
1 2 5
ans =
2 4 5
ans =
2 3 4
ans =
4 7 9
ans =
6 12 13
ans =
6 9 10 11 13 14
ans =
4 5 6 9 10 11
ans =
7 8

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by