How to call function using list element?

8 ビュー (過去 30 日間)
BoSeon Kang
BoSeon Kang 2019 年 9 月 28 日
回答済み: Stephen23 2019 年 9 月 28 日
I want to call function using list(array) element.
example :
list = {'sub_function','semi_function'};
function_list = split(list);
test = string(algoritm_list(1));
test(handles);
function sub_function(handles)
disp("sub_function")
But I can't call function this way.
how?... is it impossible??..

採用された回答

Stephen23
Stephen23 2019 年 9 月 28 日
Use str2func, e.g.:
function test()
C = {'sub1','sub2'};
F = cellfun(@str2func,C,'uni',0);
for k = 1:numel(F)
F{k}()
end
end
function sub1()
disp('hello')
end
function sub2()
disp('world')
end
Which when I run it, displays this in the command window:
>> test()
hello
world

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by