Constructor for function_handles

버전 1.3 (3.81 KB) 작성자: Rody Oldenhuis
Creates evaluable function handles for any function, possibly outside the MATLAB search path
다운로드 수: 1K
업데이트 날짜: 2020/5/2

편집자 메모: This file was selected as MATLAB Central Pick of the Week

If you ever found yourself in a situation where you could not or didn't want to add a directory to the MATLAB search path, but still needed speedy access to a function in that directory, this file is for you.
In such cases, having to change directories to gain access to the function is not the best solution: you'd always have to take care to change the current path back to what it was (even on error). Moreover, performance in those cases can be poor if you have to call this function very often.

FUNCTION_HANDLE allows you to create function handles which can successfully be evaluated without loss of performance, even if the function the handle points to is not on the MATLAB search path.

While there often are better ways to accomplish this sort of task (package directories, symbolic links, etc.), there are a few niche cases where these solutions are simply more involved than using this FUNCTION_HANDLE constructor.

Note that FUNCTION_HANDLE overloads a function present in standard MATLAB. This 'native' function is nothing more than documentation (linked to in the help for this constructor) and an error message which says that you cannot use the function to construct handles. As this is exactly what FUNCTION_HANDLE implements, this shadowing is desirable.

Example session:

>> F = function_handle('./path/to/function/myFcn.m')
F =
@myFcn

>> A = function_handle(...
{@cos, '../dir/not/on/path/myFunction.m'})
A =
@cos @myFunction

>> A{1}(pi)
ans =
-1

>> functions(A{1})
ans =
function: 'min'
type: 'simple'
file: ''

>> functions(A{2})
ans =
function: 'myFunction'
type: 'simple'
file: '/fullpath/dir/not/on/path/myFunction.m'

인용 양식

Rody Oldenhuis (2024). Constructor for function_handles (https://github.com/rodyo/FEX-function_handle/releases/tag/v1.3), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2010a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보
1.3

See release notes for this release on GitHub: https://github.com/rodyo/FEX-function_handle/releases/tag/v1.3

1.2.0.0

[linked to Github]

1.1.0.0

- small doc update; tags were messed up

1.0.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.