Main Content

sortcols

Sort columns of DataMatrix in ascending or descending order

Description

DMObjNew = sortcols(DMObj1) sorts the columns in DMObj1 in the ascending order based on the elements in the first row. For any columns that have equal elements in a row, sorting is based on the row immediately below.

example

DMObjNew = sortcols(DMObj1,Row) sorts the columns in DMObj1 in the ascending order based on the elements in the specified Row. Any columns that have equal elements in the specified row are sorted based on the elements in the next specified row.

example

DMObjNew = sortcols(DMObj1,ColName) sorts the columns in DMObj1 in the ascending order according to the column names ColName.

DMObjNew = sortcols(___,Mode) specifies whether to sort the rows in the ascending or descending order Mode for any of the previous syntaxes.

example

[DMObjNew, Indices] = sortcols(___) also returns Indices, an index vector that links DMObj1 to DMObjNew for any of the previous syntaxes. In other words, DMObjNew = DMObj1(:,idx).

Examples

collapse all

Load the MAT-file, provided with the software, that contains yeast data. This MAT-file includes three variables: yeastvalues, a 614-by-7 matrix of gene expression data, genes, a cell array of 614 GenBank® accession numbers for labeling the rows in yeastvalues, and times, a 1-by-7 vector of time values for labeling the columns in yeastvalues.

load filteredyeastdata

Create variables to contain a subset of the data, specifically the first five rows and first four columns of the yeastvalues matrix, the genes cell array, and the times vector.

yeastvalues2 = yeastvalues(1:5,1:4);
genes2 = genes(1:5,:);
times2 = times(1:4);

Create a DataMatrix object.

dmo = bioma.data.DataMatrix(yeastvalues2,genes2,times2)
dmo = 

                  0       9.5     11.5      13.5  
    SS DNA     -0.131    1.699    -0.026     0.365
    YAL003W     0.305    0.146    -0.129    -0.444
    YAL012W     0.157    0.175     0.467    -0.379
    YAL026C     0.246    0.796     0.384     0.981
    YAL034C    -0.235    0.487    -0.184    -0.669

Sort the columns in the ascending order based on Row 1.

dmo2 = sortcols(dmo,1)
dmo2 = 

                  0      11.5      13.5       9.5 
    SS DNA     -0.131    -0.026     0.365    1.699
    YAL003W     0.305    -0.129    -0.444    0.146
    YAL012W     0.157     0.467    -0.379    0.175
    YAL026C     0.246     0.384     0.981    0.796
    YAL034C    -0.235    -0.184    -0.669    0.487

Sort the columns in the descending order based on Row 1.

dmo3 = sortcols(dmo,1,"Descend")
dmo3 = 

                9.5     13.5      11.5         0  
    SS DNA     1.699     0.365    -0.026    -0.131
    YAL003W    0.146    -0.444    -0.129     0.305
    YAL012W    0.175    -0.379     0.467     0.157
    YAL026C    0.796     0.981     0.384     0.246
    YAL034C    0.487    -0.669    -0.184    -0.235

Input Arguments

collapse all

DataMatrix, specified as a bioma.data.DataMatrix object.

Row information, specified as a positive integer, vector of positive integers, character vector, string scalar, string vector or cell array of character vectors specifying row names, or logical vector.

Data Types: double | logical | char | string | cell

Column name, specified as a character vector or string scalar.

Data Types: char | string

Column sort order, specified as "ascend" or "descend".

Data Types: char | string

Output Arguments

collapse all

DataMatrix after sorting the columns, returned as a bioma.data.DataMatrix object.

Index vector that links DMObj1 to DMObjNew, returned as a numeric vector.

Version History

Introduced in R2008b