Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 基于先前排序结果的排序_Matlab_Sorting_Matrix - Fatal编程技术网

Matlab 基于先前排序结果的排序

Matlab 基于先前排序结果的排序,matlab,sorting,matrix,Matlab,Sorting,Matrix,事情是这样的 我有一个很大的矩阵,我需要根据一些列对其进行排序: B是大矩阵 A=sortrows(B,[1 4 9 10]);%Just a sample input vector 到目前为止还可以。但在下一步(我将迭代此函数)中,我需要: A=sortrows(B,[1 4 9 10 16]);%Notice I just add a new column to input vector 在下一次迭代中也会出现同样的情况 所以我的问题是,我可以在每次迭代中使用以前的排序结果吗 编辑---

事情是这样的

我有一个很大的矩阵,我需要根据一些列对其进行排序:

B是大矩阵

A=sortrows(B,[1 4 9 10]);%Just a sample input vector
到目前为止还可以。但在下一步(我将迭代此函数)中,我需要:

A=sortrows(B,[1 4 9 10 16]);%Notice I just add a new column to input vector
在下一次迭代中也会出现同样的情况

所以我的问题是,我可以在每次迭代中使用以前的排序结果吗

编辑------------------------------------

对于那些熟悉的人来说,主要的问题是一个功能选择任务。我有一个矩阵,让我们来命名它。你可以在中找到一个。在中,行是对象,列是功能。任务是基于适应度函数评估功能的子集。我不使用适应度函数,因为它不相关,而是作为一个黑匣子输入和输出输出为:

function fitnessValue=fitness(inputMatrix,featureSubset)
end
必须根据featureSubset对inputMatrix进行排序,但是根据feature set的任何排列进行排序就可以了

现在主要算法

featureSubset=[];
iter=1;
while iter<iterMax and fitnessValue<1
j=chooseFeature(IS,featureSubset) %select a feature that has not been selected yet based on some parameters 

featureSubset=union(featureSubset,j);%Add j to selected features

IS=sortrows(IS,featureSubset);%Here is the problem

fitnessValue=fitness(IS,featureSubset)
iter=iter+1;
end
featureSubset=[];
iter=1;

虽然iter这是我提出的功能,可能对将来的人有用:

function [ndx]=sort2(x,cols,oldIndex)

x=x(:,cols);    
[m,n] = size(x);

if nargin<3
    ndx = (1:m)';
else 
   ndx=oldIndex;
end

for k = n:-1:1    
    [ignore,ind] = sort(x(ndx,k));
    ndx = ndx(ind);    
end

你能提供你使用的迭代的例子吗?只是想说明一下,当你添加列
16
时,你希望列
1、4、9、10中具有相同值的行被“就地”排序根据
16
第列中的值?您是否尝试过使用
for
-循环和增量排序的简单实现?我尝试了几乎所有的方法,但遗漏了一些非常清楚的内容。我查看了sortrows源代码,发现它使用了类似于您建议的内容,但当我尝试将其分为两部分时结果是different@Shai请考虑,对于我的情况,我只需要基于输入向量的排序矩阵,序列并不重要,所以任何基于E(1 4×9 10 16)的排列的排序都可以完成。
a=sort2(IS,[1 4 9 10]);
a=sort2(IS,16,a);
b=sort2(IS,[16 1 4 9 10]);

isequal(a,b)=1