使用MATLAB的所有可能组合

发布于 2025-02-10 06:22:48 字数 173 浏览 3 评论 0原文

如果a = [1 1 2 2 2],我希望该向量的所有可能组合。 ANS:r = [1 1 2 2 2; 1 2 1 2 2; 1 2 2 1 2; 1 2 2 2 1; 2 1 1 1 2 2; 2 1 2 1 2; 2 1 2 2 1; 2 2 1 1 2 1; 2 2 2 1 1; 2 2 2 1 1 2] 有一些com吗?

If A=[1 1 2 2 2], I want all possible combinations of this vector.
Ans: R=[1 1 2 2 2; 1 2 1 2 2; 1 2 2 1 2; 1 2 2 2 1; 2 1 1 2 2; 2 1 2 1 2; 2 1 2 2 1; 2 2 1 2 1; 2 2 2 1 1; 2 2 1 1 2]
Is there some comand for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2025-02-17 06:22:48

您可以使用perms获取所有排列,并使用unique删除相同的排列。

unique(perms([1,1,2,2,2]),'rows')

You can use perms to get all permutations and remove the identical ones using unique

unique(perms([1,1,2,2,2]),'rows')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文