gpt4 book ai didi

arrays - Matlab - 数组中重复次数最多的值(不仅仅是模式)

转载 作者:太空宇宙 更新时间:2023-11-03 19:48:36 25 4
gpt4 key购买 nike

我有一个数组,其中的数字范围从 1 到 4。我需要知道哪些值重复次数更多。如果有平局,我需要知道哪些是值,以便我可以进行一些操作。

示例:

a = [1 1 1 2 2 2 3 4]
Output = [1 2]

a = [1 1 1 2 3 4]
Output = 1

a = [1 2 2 3 3 4 4]
Output = [2 3 4]

有什么想法吗?

最佳答案

使用 histunique 的替代向量化方法

uVal = unique(a);
counts = hist(a,uVal);
out = uVal(counts == max(counts));

结果:

a = [1 1 1 2 2 2 3 4];

>> out

out =

1 2

关于arrays - Matlab - 数组中重复次数最多的值(不仅仅是模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30422941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com