Main Content

colnames

Retrieve or set column names of DataMatrix object

Description

ReturnColNames = colnames(DMObj) returns ReturnColNames containing the column names in DMObj, a DataMatrix object.

example

ReturnColNames = colnames(DMObj,ColumnIndices) returns the column names specified by ColumnIndices.

DMObjNew = colnames(DMObj,ColumnIndices, ColNames) returns DMObjNew, a DataMatrix object, with columns specified by ColumnIndices set to the names specified by ColNames.

example

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 a subset of the data.

yeastvalues1 = yeastvalues(1:5,:);
genes1 = genes(1:5,:);
dm1 = bioma.data.DataMatrix(yeastvalues1,genes1,times);

Get the row names.

rnames = rownames(dm1)
rnames = 5×1 cell
    {'SS DNA' }
    {'YAL003W'}
    {'YAL012W'}
    {'YAL026C'}
    {'YAL034C'}

Get the column names.

cnames = colnames(dm1)
cnames = 1×7 cell
    {'   0'}    {' 9.5'}    {'11.5'}    {'13.5'}    {'15.5'}    {'18.5'}    {'20.5'}

Change the column names to default names.

dmNew = colnames(dm1,[1:7],true)
dmNew = 

               Col1      Col2     Col3      Col4      Col5      Col6      Col7  
    SS DNA     -0.131    1.699    -0.026     0.365    -0.246     0.478     0.435
    YAL003W     0.305    0.146    -0.129    -0.444    -0.707    -1.499    -1.935
    YAL012W     0.157    0.175     0.467    -0.379     -0.52    -1.279    -2.125
    YAL026C     0.246    0.796     0.384     0.981      1.02     1.646     1.157
    YAL034C    -0.235    0.487    -0.184    -0.669    -1.006     2.369     2.611

Change the column names to custom names.

dmNew = colnames(dm1,[1:7],{'t0','t1','t2','t3','t4','t5','t6'})
dmNew = 

               t0        t1       t2        t3        t4        t5        t6    
    SS DNA     -0.131    1.699    -0.026     0.365    -0.246     0.478     0.435
    YAL003W     0.305    0.146    -0.129    -0.444    -0.707    -1.499    -1.935
    YAL012W     0.157    0.175     0.467    -0.379     -0.52    -1.279    -2.125
    YAL026C     0.246    0.796     0.384     0.981      1.02     1.646     1.157
    YAL034C    -0.235    0.487    -0.184    -0.669    -1.006     2.369     2.611

Update row names.

dmNew2 = rownames(dmNew,[1:5],{'g1','g2','g3','g4','g5'})
dmNew2 = 

          t0        t1       t2        t3        t4        t5        t6    
    g1    -0.131    1.699    -0.026     0.365    -0.246     0.478     0.435
    g2     0.305    0.146    -0.129    -0.444    -0.707    -1.499    -1.935
    g3     0.157    0.175     0.467    -0.379     -0.52    -1.279    -2.125
    g4     0.246    0.796     0.384     0.981      1.02     1.646     1.157
    g5    -0.235    0.487    -0.184    -0.669    -1.006     2.369     2.611

Input Arguments

collapse all

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

DataMatrix columns, specified as a positive integer, vector of positive integers, character vector, cell array of character vectors containing column names, or a logical vector.

Data Types: double | logical | char | string

Flag to assign column names to the specified columns in the output DataMatrix, specified as a numeric or logical true (1) or false (0).

The number of elements in ColumnIndices must equal the number of elements in ColNames.

If you set to true, unique column names are assigned using the format col1, col2, col3, and so on.

Data Types: double | logical

Output Arguments

collapse all

Column names of DataMatrix, returned as a character vector or cell array of character vectors.

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

Version History

Introduced in R2008b