Remove specific rows from matrix
1 次查看(过去 30 天)
显示 更早的评论
I have two matrices shown below:
A =
0.2247 0.5845
0.4942 0.7303
0.5000 0.5000
0.6440 0.5408
0.6210 0.2230
0.6210 0.2230
0.2869 0.3921
1.0000 1.0000
B =
0.2247 0.5845
0.4942 0.7303
0.6440 0.5408
0.6210 0.2230
0.2869 0.3921
I would like to delete the rows in matrix A that match the rows from matrix B. How would I go about doing this?
Thanks in advance.
0 个评论
采纳的回答
Adam Danz
2019-11-23
编辑:Adam Danz
2019-11-24
If you're looking for exact matches use
However, with floating decimals it's likely that your variable values may differ slightly such as 0.28690123 vs 0.28690131. If you'd like that to be considered a match, use
To identify and remove the first match of B within A,
removeRowIdx = cell2mat(arrayfun(@(i) find(ismember(A,B(i,:),'rows'),1,'first'),(1:size(B,1))','UniformOutput',false));
A(removeRowIdx,:) = []
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!