MATLAB:比较所有元素三个数组

编程入门 行业动态 更新时间:2024-10-09 23:17:09
本文介绍了MATLAB:比较所有元素三个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有三个一维数组元素的地方都是一些价值观,我想每一个环节都在一个阵列中比较两个其他所有元素。

I have three 1-d arrays where elements are some values and I want to compare every element in one array to all elements in other two.

例如:

a=[2,4,6,8,12] b=[1,3,5,9,10] c=[3,5,8,11,15]

我想知道是否有不同的阵列(在此情况下,有3,5,8)

I want to know if there are same values in different arrays (in this case there are 3,5,8)

推荐答案

的answer由AB 给出是正确的,但它是针对特定的情况下,当你有 3 阵列您要比较。还有另外一种选择,可以轻松扩展到任意数量的任意大小的阵列。唯一的假设是,每个单独的阵列包含唯一的(即非重复的)值:

The answer given by AB is correct, but it is specific for the case when you have 3 arrays that you are comparing. There is another alternative that will easily scale to any number of arrays of arbitrary size. The only assumption is that each individual array contains unique (i.e. non-repeated) values:

>> allValues = sort([a(:); b(:); c(:)]); %# Collect all of the arrays >> repeatedValues = allValues(diff(allValues) == 0) %# Find repeated values repeatedValues = 3 5 8

如果数组包含重复的值,你就需要调用 UNIQUE 他们每个人之前,使用上述溶液。

If the arrays contains repeated values, you will need to call UNIQUE on each of them before using the above solution.

更多推荐

MATLAB:比较所有元素三个数组

本文发布于:2023-11-29 09:58:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646071.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   元素   MATLAB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!