如何从一个向量中获得不在另一个向量中的元素 [英] How to get the elements from one vector that aren't in another vector

查看:107
本文介绍了如何从一个向量中获得不在另一个向量中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很简单,但是很难为此找到合适的功能.我有一个向量a = [1 2 3 4]和另一个向量b = [1 2 6 8].我想返回a中所有不在b中的元素.在这种情况下,它将为[3 4].你如何做到的?

I know this is simple but am having a hard time finding the right function for this. I have a vector a = [1 2 3 4] and another vector b = [1 2 6 8]. I want to return all of the elements in a that aren't in b. In this case, it would be [3 4]. How do you do this?

推荐答案

您尝试使用

did you try with setdiff?

c = setdiff(a,b)

这篇关于如何从一个向量中获得不在另一个向量中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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