从数组中排除元素 [英] Exclude elements from array

查看:118
本文介绍了从数组中排除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列向量:

A = [1; 2; 3; 4; 4; 5; 5; 7]; 

我希望排除第二个矩阵B中的A元素:

I wish to exclude the elements of A that are in a second matrix B:

B = [4; 5]

最终结果应该是:

A = [1; 2; 3; 7]

我很确定使用MATLAB优雅的语法,无需编写for循环即可完成此操作,但不确定如何?

I am pretty sure using MATLAB elegant syntaxing, this be accomplished without writing a for loop, but not sure how?

推荐答案

我会使用Afilt=A(~ismember(A,B));.这将返回A中所有不在B中的元素.

I would use Afilt=A(~ismember(A,B));. This will return all elements of A which are not in B.

这篇关于从数组中排除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆