Marklab object

File: marklab.m
Location: ..\cubatch\@marklab
function MarkLab = MarkLab(Labels,Markers)
Inputs
Labels: single label object or a cell vector of label objects (in case of multi-way arrays).
Marker: char array. Each row defines a marker for when the corresponding element (i.e. a slab in the array) is assigned to a certain category.

Outputs
MarkLab: marklab object
Description
Creator function for the marklab object based on the label object.
The number of rows of MarkLab corresponds to the number of "modes" while the number of columns refers to the different possible categories.
Having the label object Labels:

> Labels = label(1:10,'Sam',[],'','Samples');

and two possible assignments: calibration set and test set, signalled respectively by the markers:

> Markers = [' C ';' T '];

A marklab object can be defined as following.

> » MarkLab = MarkLab(Labels,Markers)
> MarkLab =
> marklab object: 1-by-2

The labels (marked or unmarked) can be visualised by

> » MarkLab.labels
> ans =
> Sam 1
> Sam 2
> Sam 3
> Sam 4
> Sam 5
> Sam 6
> Sam 7
> Sam 8
> Sam 9
> Sam 10

The syntax for the marklab object is somewhat unusual.
To select (that is, to assign a certain label to a given category:

- MarkLab(1:4:10).sel = 2;
  assigns the labels 1, 5 and 9 to the test set (marked by a ' T '), i.e. to category 2. Yielding

> T Sam 1
> Sam 2
> Sam 3
> Sam 4
> T Sam 5
> Sam 6
> Sam 7
> Sam 8
> T Sam 9
> Sam 10

- MarkLab(2:4:10).sel = 1;
  yields

  T Sam 1
  C Sam 2
  Sam 3
  Sam 4
  T Sam 5
  C Sam 6
  Sam 7
  Sam 8
  T Sam 9
  C Sam 10

To deselect:

- MarkLab(5).desel = 2;
  deselect (only from category 2) object 5, obtaining

> T Sam 1
> C Sam 2
> Sam 3
> Sam 4
> Sam 5
> C Sam 6
> Sam 7
> Sam 8
> T Sam 9
> C Sam 10

If one had used instead

> » MarkLab(5).desel = 1;

no difference could have been observed as label 5 do not belong to category one.
If no assignment is made MarkLab.sel returns the position of the labels that have been assigned:

> ans =
> 1
> 2
> 6
> 9
> 10

As to yield the positions for the different categories, braces are necessary:

> » MarkLab.sel{1}
> ans =
> 2
> 6
> 10

and

> » MarkLab.sel{2}
> ans =

> 1
> 9

It is also possible to extract the number of selected elements for the different categories

> » MarkLab.dims
> ans =
> 3 2

MarkLab.dims(1), MarkLab.dims(2) are also valid, and the index refers to the category again.

In case of multi-way arrays the following example shows how to create a "multidimensional" marklab object:

> » Lab1 = label(1:10,'Var.',[],'','Mode 2');
> » Lab2 = label(1:8,'Var.',[],'','Mode 3');

> » Marklab = MarkLab({Lab1,Lab2},Markers);

Braces are necessary (right after the marklab object name) to define to which dimension the selection is referring. So

> » MarkLab{2}(1:2:8).sel = 2;

"assigns" the variables in position 1, 3, 5 and 7 of the second mode to the second category.
The labels becoming:

> » MarkLab{2}.labels
> ans =
> T Var. 1
> Var. 2
> T Var. 3
> Var. 4
> T Var. 5
> Var. 6
> T Var. 7
> Var. 8

the subreferences .dims and .sel are still available but they return, unless otherwise specified, cell vectors where each element refers to one mode:

> » MarkLab.sel{2}
> ans =
> [] [4x1 double]

In order to refer to one mode only (here the second), three subreferences are required: the mode (first braces), the required information (ex. .sel) and the category (here 2)

> » MarkLab{2}.sel{2}
> ans =
> 1
> 3
> 5
> 7

This choice was done to facilitate the use of marklab objects for (almost direct) indexing.
If one makes the additional selection (so that variables are selected both in the first and in the second mode)

> MarkLab{1}(1:3:10).sel = 2;

An index can be defined by

> Ind = MarkLab.sel{2};

If the matrix corresponding to the MarkLab object is X = [1:10]'*[1:8];

The selection of the "selected" submatrix may come as:

> » X(Ind{:})
> ans =
> 1 3 5 7
> 4 12 20 28
> 7 21 35 49
> 10 30 50 70

An equivalen results could be obtained by:

> » X(MarkLab{1}.sel{2},MarkLab{2}.sel{2})
> ans =
> 1 3 5 7
> 4 12 20 28
> 7 21 35 49
> 10 30 50 70

A subreference like

MarkLab.sel

yields in this example a cell vector containing the index for the elements (in the corresponding modes) that have been assigned to any category. Hence, by additionally selecting:

> » MarkLab{1}(2:3:10).sel = 1;
> » MarkLab{1}.labels
> ans =
> T Var. 1
> C Var. 2
> Var. 3
> T Var. 4
> C Var. 5
> Var. 6
> T Var. 7
> C Var. 8
> Var. 9
> T Var. 10

The commands

> » Ind = MarkLab.sel
> Ind =
> [7x1 double] [4x1 double]
> » Ind{1}
> ans =
> 1
> 2
> 4
> 5
> 7
> 8
> 10

NB. The 'end' statement (i.e. used as index) is not currently supported for MarkLab objects

Methods:

- length
- size
- subsasgn
- subsref
- \private\update, update labels

Author:
Giorgio Tomasi
Royal Agricultural and Veterinary University
MLI, LMT, Chemometrics group
Rolighedsvej 30
DK-1958 Frederiksberg C
Danmark
Last modified: 08 Jan. 2002
Contact: Giorgio Tomasi, gt@kvl.dk
References