how to write a code in which the output of a one function will be out put to an other function.?

4 views (last 30 days)
I have created 5 functions in different m files. v=[1,2,4,3,5]% if the function execution order, in this case, the output of function will be the input to the function 2 and output of the function 2 will be input to the function 4 and function 4 output will be input to the function 3 and so on, in the end, the final output

Answers (1)

Stephen23
Stephen23 on 14 Aug 2018
Edited: Stephen23 on 14 Aug 2018
This is easy, assuming that each function has just one input and output. Try this:
C = {@fun1,@fun2,@fun3,@fun4,@fun5}; % cell array of function handles.
val = []; % initial value.
for k = [1,2,4,3,5] % the order to call the functions in.
val = C{k}(val);
end

Community Treasure Hunt

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

Start Hunting!