フィルターのクリア

Pass m-function as parameter in m-function

2 ビュー (過去 30 日間)
Juan Carrau
Juan Carrau 2022 年 4 月 22 日
コメント済み: Juan Carrau 2022 年 4 月 25 日
So I want to pass an m-function(func2) as a parameter to another m-function (func1), so as that func1 can use func2 inside it. See for example:
  • func1.m
function [] = func1(value, another_function)
% ... code
result_from_another_function = another_function(value)
% ... code
end
  • func2.m
function [result] = func2(value)
% do something with value and return a result
end
Then in a script i would like to do something of the sort:
value = 2 % example value
func1(value, func2)
I want to do this so I can pass other functions into func1. How can i do this? Thank you in advance!

採用された回答

Bruno Luong
Bruno Luong 2022 年 4 月 22 日
Here is how you pass a function handle (it can be mfile, pfile, mexfile, appfile, anything that can run under MATLAB)
func1(value, @func2)
  1 件のコメント
Juan Carrau
Juan Carrau 2022 年 4 月 25 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by