zoukankan      html  css  js  c++  java
  • MATLAB技巧—sort和sortrows函数

    MATLAB技巧—sort和sortrows函数

    1、sort函数

    sort函数用于对数据进行排序,通过help sort命令,可以查找到sort函数的具体用法:
    Y = SORT(X,DIM,MODE)
    has two optional parameters.  
    DIM selects a dimension along which to sort.
    MODE selects the direction of the sort
       'ascend' results in ascending order
       'descend' results in descending order
    The result is in Y which has the same shape and type as X.
    上面的意思是说,在sort函数中,有两个参数,一个参数是dim,dim表示的是按照哪一维排序,如行为1,列为2;第二个参数是mode,mode表示的是按照降序或者升序排列(缺省的时候是升序排列)。

    对于矩阵

    按行升序:

    按列升序:

    从上述的结果看出,sort函数会比较矩阵中的每一个元素,将行中的每一个元素或者列中的每一个元素按照升序排列。

    若现在需要将矩阵按照行排序,可以任意指定排序比较的列。可以使用sortrows函数。

    2、sortrows函数

    SORTROWS(X,COL) sorts the matrix based on the columns specified in the
    vector COL.  If an element of COL is positive, the corresponding column
    in X will be sorted in ascending order; if an element of COL is negative,
    the corresponding column in X will be sorted in descending order. For
    example, SORTROWS(X,[2 -3]) sorts the rows of X first in ascending order
    for the second column, and then by descending order for the third
    column.数据分析师培训

    sortrows函数根据列col升序排序:

  • 相关阅读:
    练习一
    Oracle删除一个库里面的所有表
    bat脚本中,@echo on与@echo off的使用
    bat命令之执行脚本后不退出窗口
    福清游玩
    MyEclipse快捷键
    过滤器与拦截器
    Anaconda-Jupyter的简单使用
    pycharm简单配置
    4、 vim&shell
  • 原文地址:https://www.cnblogs.com/amengduo/p/9587140.html
Copyright © 2011-2022 走看看