Matlab的排序每隔一列 [英] Matlab sort every other column

查看:233
本文介绍了Matlab的排序每隔一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有看起来像这样的重复图案的数据 -

I've got data that looks like this in a repeating pattern-

years cf1  years  cf2
2010   45  2010   37
2011   39  2011   29
2012   51  2012   31
2013   25  2013   33 
2014   35  2014   28

我需要的数据或数组看起来像这样每隔一列由CFX变量排序之后。

I need the data or array to look like this after every other column is sorted by the "cfX" variable.

years cf1  years cf2
2013  25   2014  28
2014  35   2011  29
2011  39   2012  31
2010  45   2013  33
2012  51   2010  37

非常感谢你对你的帮助!

thank you very much for you help!

推荐答案

对于每个两列,您可以使用的sortRows

For each set of two columns, you can use sortrows.

for idx=1:2:size(M,2)
    M(:,idx:idx+1)=sortrows(M(:,idx:idx+1),2)
end

这篇关于Matlab的排序每隔一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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