MATLAB Answers

Erik
0

Is it allowed to publish an extension to a built-in function on File Exchange?

Asked by Erik
on 27 Jul 2016
Latest activity Edited by Erik
on 28 Jul 2016
I have a great idea for additional functionality of a built-in function from a MATLAB toolbox. For this extension to work, I'd need to use almost the entire original function's code and add my functions to it. Is this allowed?
The function in question needs other functions from the same toolbox, so my extension would not work for others without the toolbox. However, I'm still copying many lines of original MATLAB code. Is this allowed?

  0 Comments

Sign in to comment.

Products

4 Answers

Answer by Walter Roberson
on 27 Jul 2016

If you take a Mathworks function and modify it and post the new function, that would be a violation of copyright. Only people who have the appropriate toolbox are authorized to look inside at the .m, but posting on File Exchange would make that code available to the public including to people who have no MATLAB licenses at all.

  3 Comments

Do you know if there's some license agreement or terms of use of MATLAB and the File Exchange. If anywhere, it should be specified there!
@Erik: From the FEX startpage:
  1. click "About File Exchange" (LHS, below "Submit a File" button)
  2. click "MATLAB Central Terms of Use" (RHS top).
  3. click "File Echange"
will get you here:
which explains that all FEX submissions are licensed under the BSD license. Is MATLAB code itself licensed under the BSD ? No.
However it is up to MATLAB to decide what license they have given you: this is their right, and it may be different between customers.
Thanks. The terms also specify that I must be the rights owner of anything I publish, which is not the case for any part of a built-in MATLAB (toolbox) function. I'll contact support with my question and suggest I could publish it, but this is probably not allowed. Maybe they'll add it to their enhancements list, as Steven Lord has commented below.

Sign in to comment.


Answer by Steven Lord
on 27 Jul 2016

I would recommend contacting Technical Support and/or Customer Service. They will be able to give you a definitive answer, plus if you describe the enhancement you want to make they may indicate it's already implemented in a later release than the one you have or may describe a way to achieve the same results using existing tools.
If it's not possible to do that already, they can enter your description into the enhancement database. Once it's in the enhancement database, the development staff can consider implementing the enhancement request in a future release of the toolbox.

  1 Comment

Great idea, I'll consider it after I've decided whether or not to publish it myself.

Sign in to comment.


Answer by Image Analyst
on 27 Jul 2016

Yes, it's allowed. For example I use the entire code of imshow(), imread(), and many other functions in my File Exchange submissions. For example my Image Segmentation Tutorial does image segmentation, like the built in functions im2bw() and regionprops() do, but it does so much more, while using those functions inside mine. The File Exchange would have hardly any functions in it if people weren't allowed to use built-in function in them. Of course I mean calling the built-in functions, since none of use have code for the internals of those functions, unless you're a Mathworks employee.

  3 Comments

But is this what Erik is asking? While you use tools from the IPT, and do so heavily, do you modify a toolbox m-file code, then post it on the FEX? I believe that is the gist of Erik's question.
Most m-files in the toolboxes don't have very much stuff in them before they end up calling a DLL or some binary code. So you're not really going to have source code for toolbox functions. And using code built from intact toolbox functions to derive other functions is allowed - every File Exchange submission does that. Sure, he's not allowed to reverse engineer code to try to get the original code but I don't think he'd be able to do that. He says he needs/wants to use "the entire original function's code" ... but I don't think he'd be able to get to that. He can only get to the code at the function call level so I assume that's what he meant. If he does indeed have a way to get to the original source code that normally only Mathworkers have access to, then I think he should say so, but I don't think that's the case.
For example, look at the code of fft2.m: it is merely a layer on top of fftn.m and fft.m. If I want to insert functionality, e.g. I put a line of code somewhere in between the other code in fft2.m, depending on that point in the function, then I'd need to reuse and publish the contents of fft2.m with my own code within it. In other words: I can't simply call fft2.m from my own function, I really need to change it. Also, I'd give it a different name to preserve the original functionality. For the sake of the example let's call it fft2e.m
By publishing fft2e.m I'm publishing all the code from fft2.m. However, this does not contain a fully functional fft2.m: it needs other parts of the signal processing toolbox (fftn.m and fft.m). It does contain copyrighted code from the toolbox, although not functional.
Would it be allowed to publish fft2e.m the way I describe it?

Sign in to comment.


Answer by Erik
on 28 Jul 2016
Edited by Erik
on 28 Jul 2016

In the meantime I could solve the problem as follows, which is allowed I believe:
At the point(s) where I want to insert code into MATLAB's toolbox function, I could shadow the next function being called. In the example I give in a previous comment, I could want to insert some functionality into fft2.m at the point where fft is called. Suppose my extension to fft2.m is called fft2e.m. I could shadow fft by writing a function called fft.m containing the following pseudocode.
function varargout = fft(varargin)
% check who is calling fft.m
stack = dbstack;
if the last callers in stack are 'fft2' and 'fft2e' % you could even check the line number in fft2.m or the contents of its workspace
do the extended functionality to add to fft2.m before it calls fft
end
% return the output of MATLAB's built-in fft
[varargout{:}] = builtin('fft',varargin{:})
A requirement for this would be that the function you want to inject code into calls to a function at a specific point, so it can be shadowed.
The result is a function that doesn't use any code from MATLAB's proprietary function. However, the methods used to inject my own code might be error-prone. It also makes every other call to fft quite inefficient, as it needs to check if fft2 and fft2e are the caller.
Do you know of a more robust solution without making changes in a MATLAB function file itself?

  0 Comments

Sign in to comment.