Storing function handles and executing them from a cell matrix
Ältere Kommentare anzeigen
Hello,
I am wrtining a progarm which contian alot of user defined functions (around 300 unique ones). From input of boolean vector, the prograpm needs to call only for specific functions as seen below:
FunctionsToCall = {ExecuteSet1, function_1_1(input11), function_1_2(input12)...;
ExecuteSet2, function_2_1(input21), function_2_2(input22)...;
...}
for idx = 1:N
if FunctionsToCall{idx}{1}
for jdx = 1:N
input = InputMatix{idx}{jdx}
functionincell = FunctionsToCall{idx}{jdx};
output = functionincell(input);
end
end
end
function output = function_1_1(input)
%things to execute
end
function output = function_1_2(input)
%things to execute
end
.
.
.
How can I do that? my only other idea that comes to mind is to use alot of "if" statements.
take note that each function have a different input.
1 Kommentar
Rik
am 4 Mai 2023
I have some trouble understanding your setup. Try to make a MWE so we can run your code without any other dependencies and can reproduce your current setup.
Currently it looks like the functions are already executed when you create FunctionsToCall, which doesn't seem to match your intent.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!