Storing function handles and executing them from a cell matrix
Mostrar comentarios más antiguos
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 comentario
Rik
el 4 de Mayo de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!