提取在Matlab秩向量的相应值 [英] Extracting the corresponding value of a rank vector in Matlab

查看:261
本文介绍了提取在Matlab秩向量的相应值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算行列分配到一个数组(不是该数组本身)的指数,并创建包含这些排名第二矢量。

I intend to assign ranks to indices of an array (not the array itself) and create a second vector containing these ranks.

例如:

data: x=[ 3 7 2 0 5 2]
ranks: x'=[ 3 5 2 1 4 2]

分配行列指数后,我需要提取在循环的每次迭代的第k (从1开始)的最低指数的相应值,直到某些条件满足。

After assigning the ranks to the indices, I need to extract the corresponding value of the kth (starting from 1) minimum index in each iteration of a loop, until a certain condition satisfies.

例如,我需要在第一次迭代的第一最小索引的对应的值,意思的元素1中的行列向量对应的值,它等于在x向量的元素为0,而该指数这两个向量保持不变(要清楚,在X矢量重新$ p $每个元素psents用户的某些属性,因此如果指数的变化,我会失去跟踪的用户)。

For example, I need the corresponding value of the first minimum index in the first iteration, meaning the corresponding value of element "1" in ranks vector, which equals the element "0" in the x vector, while the index of both vectors remain constant (to be clear, each element in the x vector represents a certain property of a user, so if indices change, I'll lose track of the users).

根据这一程序,在第二循环中,在不考虑第一最小,我需要提取第二最小元件等

Following this procedure, in the second loop, without considering the first minimum, I need to extract the second minimum element and so on.

推荐答案

这样的问题已被要求,并回答了多次,但我似乎无法找到一个很好的副本。

This kind of question has been asked and answered on many occasions, but I can't seem to find a good duplicate.

无论如何,你可以使用的第二输出排序等级矢量给你所在的位置每个值将出现在排序结果。具体而言,在排序的第二输出的每个值,它会告诉你的你就必须抓住这在原来的矢量值的将它放在在这个相应的位置对数据进行排序。

Regardless, you would use the second output of sort on the rank vector to give you the position of where each value would appear in the sorted result. Specifically, for each value in the second output of sort, it would tell you which value in the original vector you would have to grab to place it in this corresponding position to sort the data.

您会再使用这个顺序来索引你的数据,以获得正确和所需的排序。

You would then use this ordering to index into your data to get the right and desired ordering.

具体做法是:

x=[ 3 7 2 0 5 2];
ranks = [3 5 2 1 4 2];

[~,ind] = sort(ranks);
out = x(ind);

我们得到退出

out =

     0     2     2     3     5     7

您可以验证我们在尊重看到排序的顺序排列数据拉出值

You can verify that we are pulling out values in the data that respect the sorted order seen in ranks.

这篇关于提取在Matlab秩向量的相应值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆