Matlab数据处理之issorted函数判断数组是否被排序

文章目录

展开
4.7
(3)

今天,带来Matlab中判断数组是否被排序的函数issorted。本文,主要包括issorted函数的常见用法、用法说明、实例。其中,实例包括在矢量上使用issorted、在矩阵上使用issorted、在单元格数组上使用issorted。

Matlab数据处理之issorted函数判断数组是否被排序

issorted函数帮助文档:

>> help issorted
 issorted TRUE for sorted vector and matrices.
    issorted(X), when X is a vector, returns TRUE if the elements of X
    are in sorted order (in other words, if X and SORT(X) are identical)
    and FALSE if not. X can be a 1xn or nx1 cell array of strings.
 
    For character arrays, ASCII order is used. For cell array of strings,
    dictionary order is used.
 
    issorted(X,'rows'), when X is a matrix, returns TRUE if the rows of X 
    are in sorted order (if X and SORTROWS(X) are identical) and FALSE if not.
    issorted(X,'rows') does not support cell array of strings.

issorted函数常见用法

TF = issorted(A)
TF = issorted(A, 'rows')

issorted函数用法说明

TF=issorted(A)如果A的元素按排序顺序排列,则返回逻辑1(true),否则返回逻辑0(false)。输入A可以是向量或N乘1或1乘N的字符串单元阵列。如果A和排序(A)的输出相等,则认为A已排序。

TF=issorted(A,’rows’)如果二维矩阵A的行按排序顺序排列,则返回逻辑1(true),否则返回逻辑0(false)。如果A和排序行(A)的输出相等,则认为矩阵A已排序。

只有issorted(A)语法支持A作为字符串的单元格数组。issorted(A,’rows’)语法支持A作为分类数组,但不支持A作为字符串的单元格数组。

issorted函数实例

在矢量上使用issorted

>> A = [5 12 33 39 78 90 95 107 128 131];

>> issorted(A)

ans =

     1

在矩阵上使用issorted

>> A = magic(5)

A =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9

>> issorted(A, 'rows')

ans =

     0

>> B = sortrows(A)

B =

     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9
    17    24     1     8    15
    23     5     7    14    16

>> issorted(B)
错误使用 issorted
输入必须为矢量,或者必须指定 'rows'。
 
>> issorted(B,'rows')

ans =

     1
Matlab数据处理之issorted函数判断数组是否被排序

在单元格数组上使用issorted

>> x = {'one'; 'two'; 'three'; 'four'; 'five'};
>> issorted(x)

ans =

     0

>> y = sort(x)

y = 

    'five'
    'four'
    'one'
    'three'
    'two'

>> issorted(y)

ans =

     1

共计3人评分,平均4.7

到目前为止还没有投票~

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

原创文章,作者:古哥,转载需经过作者授权同意,并附上原文链接:https://iymark.com/program/matlab/issorted-function-usage.html

(0)
上一篇 2022年12月26日 20:36
下一篇 2022年12月31日 12:21

你可能感兴趣的文章

  • Matlab fimplicit3根据三维影函数绘制图形

    文章目录 展开常见用法语法说明绘制三维隐函数指定绘图区间修改隐式曲面的外观创建后修改隐曲面 4 (2) 前面,我们讲过两个变量的隐函数绘图函数fimplicit的用法:Matlab…

    2021年02月10日
    0303
  • Matlab数据处理之移动总和movsum函数

    文章目录 展开movsum函数常见用法movsum函数语法说明movsum函数实例向量的中心移动和向量的尾部移动和矩阵的移动和包含 NaN 元素的向量的移动和基于样本点计算移动和仅…

    2023年01月07日
    0104
  • Matlab快速入门之线性代数:幂和指数

    文章目录 展开正整数幂逆幂和分数幂逐元素幂平方根标量底矩阵指数处理较小的数字 4.3 (3) 本文属于Matlab快速入门之线性代数的第三篇,即幂和指数 ,主要包括正整数幂、逆幂和…

    2022年09月25日
    0322
  • Matlab快速入门之数组索引

    4.3 (3) 正如上一篇文章所述,Matlab中的所有变量都可以看成数组或矩阵。那么我们获取数组中某个位置的值,就需要用到数组索引的功能。文中,以二维矩阵中某些特定位置的元素为例…

    2022年09月06日
    0458
  • Matlab极坐标绘制散点图polarscatter

    文章目录 展开常见用法语法说明极坐标中创建散点图使用已填充标记并设置标记大小使用具有不同大小和颜色的标记绘图之前从度转换为弧度合并两个散点图创建散点图之后进行修改 3.8 (5) …

    2020年12月28日
    01.3K
  • Matlab数据处理之排序函数sort

    文章目录 展开sort函数基本用法sort函数用法介绍sort函数实例按升序排序向量按升序排序矩阵行按降序对矩阵列排序排序和索引日期时间数组排序三维数组 4.7 (3) 今天带来M…

    2022年12月24日
    078

发表回复

登录后才能评论
本站APP
微信小程序