gpt4 book ai didi

matlab - 如何在 Matlab 中找到二维矩阵排列后的映射

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

我有两个二维矩阵 A、B,其中 B 是由 A 的(按行)排列生成的。A 中有一些重复记录(B 中也是如此)。我想找到产生 B 的映射。我正在使用 Matlab。只有一种解决方案对我来说就足够了。

示例:

A = [ 2 3 4; 4 5 6; 2 3 4];
B = [ 4 5 6; 2 3 4; 2 3 4];

映射将是:

p = [3 1 2]   // I want this mapping, however the solution p= [2 1 3] is also correct and acceptable

其中 A = B(p,:) 在 Matlab 中。//已编辑

问候

最佳答案

低垂的果实首先。
假设没有重复的行:

 % compute the permutation matrix
P = all( bsxfun( @eq, permute( A, [1 3 2]),permute(B,[3 1 2]) ), 3 );
[~, p] = max(P, [], 2 ); % gives you what you want

如果有重复,我们需要在 P 的行/列中“打破联系”:

 n = size(A,1);
bt = abs( bsxfun(@minus, 1:n, (1:n)' ) )/n; %//'
[~, p] = max( P+bt, [], 2 );

关于matlab - 如何在 Matlab 中找到二维矩阵排列后的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17148713/

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