如何根据另一个矩阵的costrain对矩阵的行进行排序?

How to sort rows of a matrix based on the costrain of another matrix?

像我的 MPU6050,6 面法是一种非常便宜且快速的校准加速度计的方法,here a great description of the method.

我进行了 6 次测试以根据 g 向量校准加速度计。

之后,我建立了一个矩阵,并在每一行中存储了以 m/s^2thanks to this question i automatically calculated the mean for each column in each file 表示的每个轴的平均值。

测试是随机进行的,我测试了所有六个位置,但我没有遵循任何路径。 因此,我根据 Y 矩阵(我的参考矩阵)的排序手动对最终矩阵进行了排序。 Y 元素是固定的。

手动排序的矩阵如下

这是我如何手动对矩阵进行排序的

    meanmatrix=[ax ay az];
    mean1=meanmatrix(1,:);
    mean2=meanmatrix(2,:);
    mean3=meanmatrix(3,:);
    mean4=meanmatrix(4,:);
    mean5=meanmatrix(5,:);
    mean6=meanmatrix(6,:);
    meanmatrix= [mean1; mean3; mean2; mean4;mean6;mean5];

基于 Y 矩阵约束如何在不知道的情况下对我的矩阵进行排序 "a priori" 测试存储在行中?

假设加速度计的偏差不大,您可以查看矩阵的行,看看与 Y 矩阵中的哪些行匹配。

sorted_meanmatrix = zeros(size(meanmatrix));
for rows = 1:length(Y)
    % Calculates the square of distance and see which row has a nearest distcance 
    [~,index] = min(sum((meanmatrix - Y(rows,:)).^2, 2)); 
    sorted_meanmatrix(rows,:) = meanmatrix(index,:);
end