필터 지우기
필터 지우기

Is there a way to use my own function file for a Matlab function?

조회 수: 3 (최근 30일)
Renat
Renat 2018년 1월 11일
편집: Renat 2018년 1월 12일
Dear Matlab users,
I would like to know if it is possible to substitute a Matlab function with my own .m file? Why I want do to this: I process a lot of imaging data and I seem to run out of Image_Toolbox licenses sooner than Matlab licenses. The processing pipeline seems to use only `imerode` function from the toolbox, so I wrote my own function `own_imerode.m`. Luckily, it is quite straight-forward. However, I would like not to replace `imerode` with `own_imerode` throughout the code for two reasons - backward compatibility and hassle of going through the code. Instead, I was wondering if it is possible to tell Matlab to somehow use `own_imerode` when `imerode` is called, like an alias in a bash shell? I guess, one way would be to call my function also `imerode` and place the path to it on top of the list. Is there another way?
Best, Renat.

채택된 답변

Andreas Goser
Andreas Goser 2018년 1월 12일
Renat, the root cause appears to be a lack of purchased toolboxes. Also you seem to process a lot of images. So I suggest you also look for accessing a cluster. You might have a MATLAB Distributed Computing Server license at your institution.
Beside that, I would not fiddle with the installation. You may want to a simple IF THEN ELSE statement at the beginning that looks for the toolbox being available and if yes use it and if not the alternative way. Command to use could be:
license('test','Image_Toolbox')
  댓글 수: 1
Renat
Renat 2018년 1월 12일
편집: Renat 2018년 1월 12일
I have access to an HPC cluster and this where I tun into the problem. It looks like after New Year the number of IPT licenses halved. So I looked into the processing pipeline code and realized that we don't really need IPT and I can use `conv2` instead.
I like the idea of checking for an available license and use my version if there is none. Thank you for the suggestion, I think I will use that!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2018년 1월 11일
The defined route is to use the same function name and have the function earlier on your search path.
You can reduce the impact on other code by putting your imerode into a directory named private under the directory that calls the function. https://www.mathworks.com/help/matlab/matlab_prog/private-functions.html

John D'Errico
John D'Errico 2018년 1월 11일
편집: John D'Errico 2018년 1월 11일
That is exactly how to solve the problem - just put it in a directory on your search path above the IPT directory.
Note that this also effectively disables the IPT imerode function, so if you ever need to use any capabilities of that tool that are not in your own code, it is no longer available to you. To restore access to the old imerode, you would need to change the search path, or delete or rename your version.
You may get warning messages from MATLAB, that your function steps on existing code. At least when you use it initially, but that warning seems to go away after the first use.
function chol(A)
disp('The sky is falling')
end
chol(2)
The sky is falling
One other way to temporarily recover use of the original tool is to use builtin, although I think that will only apply to actual builtin tools like chol. Toolbox functions seem not to be recognized by builtin.
L = builtin('chol',2)
L =
1.4142
  댓글 수: 1
Renat
Renat 2018년 1월 12일
The code uses the IPT imerode function to do an erosion using a line strel. This is very easily replaced with `conv2` function. I dont need its other capabilities.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by