主要内容

Issortedrows

确定是否对矩阵或表行进行排序

描述

example

tf =Issortedrows(A)返回逻辑标量1(真的)当矩阵的第一列的元素A按升序列出。否则,Issortedrows返回0(false). When the first column has consecutive repeated elements,Issortedrowsdetermines whether the next column is in ascending order, and repeats this behavior for succeeding equal values.

example

tf =Issortedrows(A,column)返回1何时A根据向量中指定的列进行排序column。例如,issortedrows(a,[4 6])首先检查是否第四列A按顺序排列,然后检查第六列是否按顺序划分以打破领带。

example

tf =Issortedrows(___,方向)当第一列的第一列返回1Ais in the order specified by方向对于以前的任何语法。例如,Issortedrows(A,'monotonic')checks if the first column ofA处于上升或降序。方向也可以是代表每列要检查的多个方向的字符阵列。例如,Issortedrows(A,[2 3],{'ascend' 'descend'})checks if the second column ofA按升序顺序,然后检查第三列是否按降序打破领带。

example

tf =Issortedrows(___,姓名,Value)指定用于检查排序顺序的其他参数。例如,issortedrows(a,“比较”,“ ABS”)检查第一列中的元素是否A按大小分类。

example

tf =Issortedrows(tblA)checks if the rows of a table are in ascending order based on the elements in the first variable. If elements in the first variable are repeated, thenIssortedrows检查第二个变量中的元素,依此类推。

IftblA是时间表,然后Issortedrowschecks if the rows oftblA根据其行时间按顺序排列。时间表的行时间沿时间表的第一个维度标记行。

example

tf =Issortedrows(tblA,'RowNames')检查表是否根据其行名称按顺序排列。表的行名称沿表的第一维标记行。

当该语法不支持金宝apptblAis a timetable.

example

tf =Issortedrows(tblA,rowdimname)检查表的行是否由行标签排序rowdimnamealong the first dimension.

  • IftblA是一个表,然后标签为行名。

  • IftblA是时间表,然后the labels are row times.

example

tf =Issortedrows(tblA,var)根据变量中的元素检查表的行是否按顺序排列var。例如,如果AgeWeight是变量tblA, thenissortedrows(tbla,{'age','strigh'})检查行是否按年龄为升序,然后按重量打破领带。

  • IftblAis a table with row names, thenvarcan include the row names.

  • IftblA是时间表,然后var可以包括行时间。

example

tf =Issortedrows(___,方向)检查表是否按照指定的顺序排序方向for any of the previous table syntaxes.方向can be a single sort order such as“下降”或者“单调”, which is applied to each specified variable, row name, or row time.方向can also be a cell array whose elements contain different sort orders for each specified variable, row name, or row time thatIssortedrowsoperates on.

example

tf =Issortedrows(___,姓名,Value)指定用于排序表的其他参数。例如,issortedrows(tbla,'var1',“丢失平台”,“ first”)checks that missing elements invar1, such asNaN或者NaT,放置在桌子的开头。

例子

collapse all

创建一个矩阵,并根据第一列中的值确定其行是否按顺序排列。由于第一列具有重复元素,sorlooks to the second column to determine whether the matrix rows are sorted.

a = [1 2 9;1 5 8;4 0 7]
A =3×31 2 9 1 5 8 4 0 7
tf =issortedrows(a)
tf =logical1

确定是否行A根据第三列中的值按升序顺序排列。

tf =Issortedrows(A,3)
tf =logical0

确定是否行A根据第三列中的值以降序为顺序。

tf =Issortedrows(A,3,“下降”)
tf =logical1

创建一个包含复数的矩阵,并根据第一列中元素的实际部分确定其行是否按顺序排列。由于第一列中的元素具有相等的实际零件,因此Issortedrows然后检查虚构的零件以打破领带。

a = [1+i 2i;1+2i 3+4i]
A =2×2复合物1.0000 + 1.0000i 0.0000 + 2.0000i 1.0000 + 2.0000i 3.0000 + 4.0000i
tf =Issortedrows(A,'ComparisonMethod','真实的')
tf =logical1

For a table that describes patient information for five people, determine how the rows of the table are sorted.

创建一个带有四个变量的表,并确定表的行是否基于年龄的上升顺序。由于年龄变量包含重复元素,Issortedrows然后检查下一列(高度)打破领带。

lastName = {'甜的';'雅各布森';'Wang';'Joiner';'伯杰'}; Age = [38;38;40;43;49]; Height = [69;71;64;67;64]; Weight = [176;163;131;133;119]; BloodPressure = [124 93; 109 77; 125 83; 117 75; 122 80]; tblA = table(Age,Height,Weight,BloodPressure,'Rownames',LastName)
tbla =5×4桌年龄高度体重血液压力___ ______ ______ _____________甜蜜38 69 176 124 93 Jacobson 38 71 163 109 77 Wang 40 64 131 125 83 Joiner 43 67 133 117 75 Berger 49 64 119 122 80
tf = issortedrows(tbla)
tf =logical1

Check if the table rows are sorted by last name, which are the row names fortblA

tf = issortedrows(tbla,'Rownames')
tf =logical0

检查表行是否按年龄升级顺序,然后按重量下降顺序。

tf = issortedrows(tbla,{'年龄','重量'},{“上升”,“下降”})
tf =logical1

创建一个时间表,并检查时间表的行是否基于行时间的升序顺序。还要检查丢失的元素是最后放置的。

时间= [秒(1:3)Nan Nan]';tt =时间表(时间,[98; 97.5; 97.9; 98.1; 99.9],[120; 111; 119; 117; 117; 112],,...'variablenames',{'Temperature','距离'})
tt =5×2时间表时间Temperature Distance _______ ___________ ________ 1 sec 98 120 2 sec 97.5 111 3 sec 97.9 119 NaN sec 98.1 117 NaN sec 99.9 112
tf =Issortedrows(TT,'Time',“缺失”,'last')
tf =logical1

Input Arguments

collapse all

输入数组,指定为列向量或矩阵。

数据类型:双倍的|单身的|int8|INT16|INT32|INT64|UINT8|UINT16|UINT32|Uint64|logical|char|细绳|分类|约会时间|duration
Complex Number Support:是的

列排序向量, specified as a nonzero integer scalar or a vector of nonzero integers. Each specified integer value indicates a column to check for sort order. Negative integers indicate that the sort order is descending.

分类方向,指定为以下一个:

  • “上升”(默认) - 检查数据是否按升序顺序进行。数据可以包含连续的重复元素。

  • “下降”- 检查数据是否按降序订购。数据可以包含连续的重复元素。

  • “单调”— Checks if data is in descending or ascending order. Data can contain consecutive repeated elements.

  • “ strictascend'- 检查数据是否严格升序。数据不能包含重复或丢失的元素。

  • “ strictdescend'— Checks if data is in strictly descending order. Data cannot contain duplicate or missing elements.

  • 'strictmonotonic'— Checks if data is in strictly descending or strictly ascending order. Data cannot contain duplicate or missing elements.

方向也可以是包含这些字符向量列表的单元格数组,其中列表中的每个元素都对应于A。例如,issortedrows(a,[2 4],{'ascend''descend'})first checks if the rows ofA根据第二列按升序顺序排列。然后,打破领带,Issortedrows检查行是否基于第四列的降序顺序。

Ifcolumn指定,然后单元格数组中的元素数必须与column。Whencolumn未指定,单元阵列必须包含每个列的元素A,或应用于所有列的单个元素。

数据类型:char|细胞

输入表, specified as a table or a timetable. Each variable intblA必须是有效的输入种类或者sor

数据类型:桌子|时间表

输入表或时间表的第一维的名称,指定为字符向量。

  • IftblAis a table with row names, thenrowdimname是表的第一维的名称。默认情况下,第一个维度的名称为'Row'。Dimension names are a property of tables. You can access the dimension names oftblA使用tblA.Properties.DimensionNames

  • IftblA是时间表,然后rowdimname是行时向量的名称。您可以在创建时间表时指定其名称,例如时间或者日期。You can also access the dimension names usingtblA.Properties.DimensionNames

例子:如果是桌子T有行名,您使用T.Properties.DimensionName{1} = 'Name', thenissortedrows(t,'name')检查表是否按行名为排序。

例子:If a timetableTT有一个时间向量名为日期, thenIssortedrows(TT,'Date')检查时间表是否按日期和时间对日期包含。

数据类型:char

排序变量,指定为标量整数,整数的向量,变量名,可变名称的单元格数组或逻辑向量。var表示表变量要排序。

If an element ofvaris a positive integer, thenIssortedrows检查是否在相应变量中的行是否在tblAare in ascending order. If an element ofvar是一个负整数,那么Issortedrows检查是否在相应变量中的行是否在tblA处于降序。

例子:issortedrows(tbla,{'height','strige'})checks if the rows oftblA按顺序排序,首先由变量高度,然后通过变量Weight至break ties.

例子:Issortedrows(TBLA,[1 4])首先检查表行是否基于第一个变量的升序顺序,然后通过根据第四变量检查行是否按上升顺序进行打破领域。

例子:Issortedrows(TT,{'Time','X'})检查时间表的行是否按顺序排列,然后通过根据表变量检查行是否按顺序排列来打破纽带'X'

数据类型:双倍的|单身的|char|细胞|logical

姓名-Value Pair Arguments

Specify optional comma-separated pairs of姓名,Value参数。姓名is the argument name and价值是相应的值。姓名必须出现在引号中。您可以按任何顺序指定几个名称和值对参数NAME1,Value1,...,Namen,Valuen

例子:issortedrows(a,“缺失”,“最后”)

放置缺失值(NaN,NaT,<未定义>, 和失踪) specified as the comma-separated pair consisting of“缺失”和one of the following:

  • 'auto'- 要求丢失的元素最后放置以进行上升订单,并首先放置降序以返回1。

  • 'first'- 丢失的元素必须先放置以返回1。

  • 'last'- 丢失的元素必须最后放置才能返回1。

元素比较方法, specified as the comma-separated pair consisting of'ComparisonMethod'和one of the following:

  • 'auto'— Check if the rows ofA真实(A)什么时候A是真实的,并检查AABS(A)什么时候Ais complex.

  • '真实的'— Check if the rows ofA真实(A)什么时候A是真实的或复杂的。如果列的元素具有连续相等的真实零件,请检查imag(A)至break ties.

  • 'abs'— Check if the rows ofAABS(A)什么时候A是真实的或复杂的。If a column has elements with consecutive equal magnitude, then check角度(a)在间隔(-π,π)中打破领带。

扩展功能

看Also

||

Introduced in R2017a