remove row of matrix inside cell

1 回表示 (過去 30 日間)
NA
NA 2019 年 8 月 16 日
編集済み: Stephen23 2019 年 8 月 16 日
I have A
A={[1,2;4,5;8,9],[1,2,3;4,5,6;1,4,5;2,4,5],[3,4,5,6;1,2,3,4;8,9,0,8;3,4,5,6]}
B={[1;3],[2;4],[2]}
I want to remove B rows from A.
I use this code, but it has a error
cellfun(@(m,n)m(n,:)=[],A,B,'uni',0);
result should be
A={[4,5],[1,2,3;1,4,5],[3,4,5,6;8,9,0,8;3,4,5,6]}

採用された回答

Stephen23
Stephen23 2019 年 8 月 16 日
編集済み: Stephen23 2019 年 8 月 16 日
You could use cellfun like this:
>> F = @(m,x) m(setdiff(1:size(m,1),x),:);
>> C = cellfun(F,A,B,'uni',0);
>> C{:}
ans =
4 5
ans =
1 2 3
1 4 5
ans =
3 4 5 6
8 9 0 8
3 4 5 6
or use a simple for loop:
>> for k = 1:numel(A), A{k}(B{k},:) = []; end
>> A{:}
ans =
4 5
ans =
1 2 3
1 4 5
ans =
3 4 5 6
8 9 0 8
3 4 5 6

その他の回答 (0 件)

カテゴリ

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