4

table() has been a standard function in MATLAB since R2013b. As far as I can see from the documentation, there's nothing special about table, compared to sum, cell, struct, or any other builtin function.

However, when I try to run the function using builtin('table',var1,...varN) I get an error saying:

Error using builtin

Cannot find builtin function 'table'

Investigating this further shows that it is in fact not considered a builtin function:

which('cell')
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\cell)

which('table')
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\@table\table.m  % table constructor
|
Not builtin

Investigating further:

which cell2mat
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\cell2mat.m

which mat2cell
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\mat2cell.m

which table2array
C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\table2array.m

which struct2cell
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\@struct\struct2cell)  % struct method

which cell2struct
built-in (C:\Program Files\MATLAB\R2014b\toolbox\matlab\datatypes\@cell\cell2struct)  % cell method

So, cell is builtin while table is not. cell2struct is builtin while cell2mat is not.

Why is this, and is there a simple way to call overloaded standard functions that aren't considered builtin by MATLAB?


If you think the why part is "too broad", please disregard it and jump to the last part of the question.

Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
  • 1
    Built-ins are generally compiled due to their frequency of use and/or take an undesirable amount of time to run as `*.m` files. There used to be a tech doc somewhere but I can't find it. – sco1 Feb 04 '16 at 14:13
  • Makes sense =) But wouldn't it make sense to compile `cell2mat` if they compile `cell2struct`? – Stewie Griffin Feb 04 '16 at 14:19
  • Maybe. But as is often the case with development, dev teams may have internal knowledge that makes things not as simple as they seem to folks outside. – sco1 Feb 04 '16 at 14:21
  • @StewieGriffin: [compiled is not always faster](http://stackoverflow.com/questions/20166847/faster-version-of-find-for-sorted-vectors-matlab/20167257#20167257), often used does not mean that it should be compiled. – Daniel Feb 04 '16 at 14:23
  • To answer the explicit question, the "simple" method would probably be to use `which` with `cd` and `feval`, similar to what I did [here](http://stackoverflow.com/a/35153710/2748311) – sco1 Feb 04 '16 at 14:23
  • @excaza: which won't tell you the path. – Daniel Feb 04 '16 at 14:27
  • @Daniel what? `a = which('table')` returns the path... – sco1 Feb 04 '16 at 14:28
  • Yes it does, but once you have a different function called `table` it no longer works. I think this is the interesting use case for such a function. – Daniel Feb 04 '16 at 14:29
  • 3
    Of course it works, use the `'-all'` flag and parse the returned cell array for the function located in the 'MATLAB' toolbox. – sco1 Feb 04 '16 at 14:32

2 Answers2

2

The documentation page for builtin gives a clear definition:

A built-in function is part of the MATLAB executable. MATLAB does not implement these functions in the MATLAB language. Although most built-in functions have a .m file associated with them, this file only supplies documentation for the function.

Daniel
  • 36,610
  • 3
  • 36
  • 69
2

You can find the native function(s) by something like:

allTables = which  ( '-all', 'table' )
allTables(cell2mat(strfind ( allTables, matlabroot )))

Its not fullproof and for some functions (e.g. sum) there are a lot in the root folders...

matlabgui
  • 5,642
  • 1
  • 12
  • 15