10a
10a

Reputation: 429

What does the Matlab vector operation myVector.(':')(':') do?

I came across the following expression in the function mavolcanoplot.m:

X = X.(':')(':');

I tried it with a simple example X = [1 2 3] but then I got

Struct contents reference from a non-struct array object.

Since I don't know what the expression does, I don't know what X should look like to test it.

Can anyone tell me what the expression does?

Upvotes: 2

Views: 80

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

According to the documentation,

When using dot indexing with DataMatrix objects, you specify all rows or all columns using a colon within single quotation marks, (':').

Take a look at this example:

import bioma.data.*
dmo = DataMatrix(rand(3,3), {'A', 'B', 'C'}, {'X','Y','Z'})

dmo = 

         X          Y          Z      
    A    0.69908    0.54722    0.25751
    B     0.8909    0.13862    0.84072
    C    0.95929    0.14929    0.25428

>> %to extract all rows and first two columns (X and Y)
>> %you can specify any of column scripts and column labels
>> %same goes for rows
>> dmo.(':')(1:2)   % or  dmo.(':')({'X','Y'})

ans =

    0.6991    0.5472
    0.8909    0.1386
    0.9593    0.1493

>> dmo.(':') %or dmo.(':')(':')  to extract all rows and columns

ans =

    0.6991    0.5472    0.2575
    0.8909    0.1386    0.8407
    0.9593    0.1493    0.2543

Furthermore, specifying a row/column label that doesn't exist gives 1 i.e.

>> dmo.('e')('X')

ans =

     1

and end cannot be used for indexing.

>> dmo.(end)('X')
Error: The end operator must be used within an array index
expression.

Upvotes: 3

Related Questions