File Exchange

image thumbnail

when - when a function was introduced by MATLAB

version (1.82 KB) by Reza Ahmadzadeh
This function shows the version in which the input function was introduced.


Updated 24 Jul 2019

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The input to this function is a matlab/simulink function name, such as 'rand' as a string. The function checks the version in which the input function was introduced. This function also accepts a group as input functions to check. See the following examples:
Example 1:
>> when('rand')
## rand is a built-in function (Introduced before R2006a)
Example 2:
func_name = {'rand','plot','grid','findstr','weboptions'};
## rand is a built-in function (Introduced before R2006a)
## plot is a built-in function (Introduced before R2006a)
## grid is a Matlab function or an ordinary m-file (Introduced before R2006a)
## findstr is a built-in function (Introduced before R2006a)
## weboptions is a Matlab function or an ordinary m-file (Introduced in R2014b)

Cite As

Reza Ahmadzadeh (2021). when - when a function was introduced by MATLAB (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (11)


Of course, I expect the formatting to get destroyed when I post this, but here goes:

if isempty(idx)
str1 = 'No information found';
str1 = str(1,idx:idx+200);
linebreak = strfind(str1,newline);
str1 = str1(1:linebreak(1)-1);
while ~isempty(str1)
% no, i'm not using split() or contains(),
% since those will cause version dependency
[tok str1] = strtok(str1,'<>');
if ~isempty(strfind(tok,'R20'))
str1 = tok;
strr = ['## [' fname ']' w ' (' str1 ').'];

This seems to work fine for me. This should find the right string if it's between the classname and the end of the current line, provided the current line ends within 200 chars.


Wasn't returning any version info (empty string)
Line 76:
str1 = str(1,idx+24:idx+47);
This is getting messed up and not selecting the right part of the string. I imagine this is because the <strong> tag probably used to be something with fewer characters. I just shifted it over a bit
str1 = str(1,(idx+24:idx+47)+4);
but looking for delimiting characters would probably be more robust.

zy lei

That's quite an amazing work. It helps me to deal with the program's compatibility for some old men.
A suggestion is that can you extract release notes, suppose it may help us improve compatibility a lot.

John D'Errico

Thank you. Something that belongs as part of MATLAB! If I had any qualms, it is that I wish it worked for toolbox functions too. As a FEX contributor and person who answers questions on Answers, one thing that I frequently need to do is check when a function was released.

A more extreme wish is that it show the complete release history, telling the user what changes were made and in what release. That is surely beyond the scope of this code though.

And then for those of us who will dare to dream, I want a whenwill utility. That would tell me when will something be introduced, in the future. (Only kidding here.)

The prosaic part of me who will give this a rating says 5 stars anyway.

Reza Ahmadzadeh

@Frederick Zittrell and @Addy - Thanks for the comments.


Not sure of it is working or not..
>> when('hilbert')
## [hilbert] is a Matlab function or an ordinary m-file (No information found).
>> when('feedforwardnet')
## [feedforwardnet] is a Matlab function or an ordinary m-file (No information found).
>> when('plot')
## [plot] is a built-in function (No information found).

Frederick Zittrell

Very useful!
However, I needed to adapt your code a bit:
- Doc pages are only accessible via https; your code queries http URLs.
- Some doc pages are named with the lower-case version of the function name (e. g. mustBeMember is only accessible via, so I added another 'isemtpy(str)' check that queries the doc page with 'lower(fname)'.



Reza Ahmadzadeh

Thank you @ Stephen Cobeldick! I consider fixing the bugs.

Stephen Cobeldick

A very tidy submission with neatly written code, a short but clear description and help. For most standard inbuilt functions it works well, as per its help:

>> when('ismac')
## [ismac] is a Matlab function or an ordinary m-file (Introduced in R2007a).

However there is are a few minor bugs with some edge-cases:

1. If no inbuilt/MATLAB function is found then an error is thrown. This can be easily fixed by adding an |else| statement at the end of the local function |checkFunctionName|:

strr = sprintf('## [%s]%s.',fname,w);

This is easy to implement as the author had already generated the required message strings in variable |w|, but for whatever reason did not use them for the non-function cases.

2. If the name of a non-MATLAB (i.e. your own) function is provided then this submission gets a bit confused and returns the wrong error message:

>> when('num2words')
Error! check your connection.
Connection error.

This occurs because it passes the |exist| test, but then cannot find any online documentation. This also occurs for functions without online documentation:

>> when('jet')
Error! check your connection.
Connection error.

This lack of one-to-one correspondence between using |exist| on the local MATLAB installation and yet accessing the most-up-to-date-version online means it is also not possible to check the date of functions not installed on the local machine:

>> when('uniquetol')
## [uniquetol] does not exist.

Perhaps some check if a function |exist|s but is not online could solve this.

Overall this is a handy function, but could do with a bit of testing and thought for some of these edge-cases. It would also be simplified by using |fprintf| inside the local function |checkFunctionName| and not returning a variable to display.

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!