1

I was trying to create a DataMatrix variable by calling the DataMatrix() function. But that function doesn't exist. If I type this:

>> DataMatrix

I got this error message:

Undefined function or variable 'DataMatrix'.

I did install the Bioinformatics Toolbox and my version is 2016b on Mac

Any ideas?

Code42
  • 2,292
  • 1
  • 17
  • 22
  • 1
    I think the only explanation is that your toolbox hasn't been installed properly (such as not being on the [MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html)). There's not much we can do to help you without more info. – gnovice Jun 08 '17 at 20:05
  • 2
    @gnovice Could be a coincidence but I can reproduce his error. Using `exist` also gives `0`. Completing the name using tab also doesn't give me anything. Furthermore, `help DataMatrix` gives `DataMatrix not found` but `doc DataMatrix` opens its documentation. I can also reproduce this error with other functions of the Bioinformatics Toolbox such as `dmarrayfun`, `dmwrite` etc. (R2016a on Win10) – Sardar Usama Jun 09 '17 at 00:34
  • 3
    I have voted to reopen, this is a legit question, nothing to do with "undefined functions" or "badly installed package". The DataMatrix class is enclosed in a "Package" / Namespace and needs to be accessed accordingly. On my installation it's the `bioma` package, which contains a `data` subpackage, which contains the class. To create an instance you will either have to type something like `D = bioma.data.DataMatrix([1,2;3,4])` or `import bioma.data.DataMatrix` `D = DataMatrix([2,3;4,5])`. Yours is likely the same, but check your installation just in case. I'll give more details if re-opened. – Tasos Papastylianou Jun 10 '17 at 22:40
  • 1
    Note that what @Tasos is talking about is [clearly written in the documentation](https://www.mathworks.com/help/bioinfo/ref/datamatrix.html) which I found by googling "matlab datamatrix". – Andras Deak -- Слава Україні Jun 10 '17 at 22:57

1 Answers1

5

As @Andras mentioned in the comments, the procedure to import and use this class is already mentioned in the documentation for the class (though you might be forgiven if you missed it, as it's not on the top part of the page dealing with syntax).


The tl;dr version is that you should either access the class constructor as, e.g.:

D = bioma.data.DataMatrix(...);

or, import the class from the package / namespace first, and then use it directly, i.e.:

import bioma.data.DataMatrix;
D = DataMatrix(...);

Explanation

The reason you need this step in the first place, is because this class is enclosed inside a "package" (a.k.a. a "namespace"). Read the section called "Packages Create Namespaces" in the matlab documentation to find out more what this means.

However, in principle it boils down to the fact that, if you have a folder whose name has a + prefix, then this acts as a namespace for the functions contained within.

So, if you have a folder called +MyPackage on your path, and this contains a function m-file called myfunction.m (but this is not in your path), then you can access this function in the matlab terminal by typing MyPackage.myfunction().

Or, you can import MyPackage.myfunction from that package / namespace and then use myfunction directly.

So, going back to DataMatrix, you will see that if you search where the class definition is located in your matlab folder, you'll find it here:

./toolbox/bioinfo/microarray/+bioma/+data/@DataMatrix/DataMatrix.m

and presumably ./toolbox/bioinfo/microarray is already in your path.

I.e. the bioma package/namespace is in your path, and you can access the data package/namespace below it, and then the class definition for DataMatrix by doing bioma.data.DataMatrix.


PS: Furthermore, the "@" prefix in front of a folder name denotes a class folder, containing the constructor and class methods. If this "@folder" is in your path (or imported etc), then this means you have access to the underlying constructor. This is a remnant from matlab's old object-oriented style, before the classdef keyword was introduced. You can read more about class directories here if you're interested.

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57