Create an array of n function handle
6 views (last 30 days)
How can I create a set of ode equations?
fun1 = @(t,x,k) x-k;
I want to generate a function of n entries like:
funN = @(t,x,k) [ x(1)-k
I want to run the program for different values of n, so I can't create the full function handle bu hand.
Guillaume on 12 May 2016
Edited: Guillaume on 12 May 2016
I'm not sure why your anonymous functions take a t input that they don't use. Anyway:
funN = @(~, x, k, N) reshape(x(1:N) - k, , 1);
and to create a cell array of them:
N = 10; %for example
allfuns = arrayfun(@(n) @(t, x, k) funN(t, x, k, n), 1:N, 'UniformOutput', false);