I have the following function:
function F = farray (f,N)
F = {@(t) zeros(N,1)};
for i=1:N
if mod(i,2)==0
F{i}=f(t);
end
end
F = cell2mat(F);
end
f is a function handle of time, that is f=@(t)f(t). N dictates the size of the output array F. Similar to f, F is also a function of time. I would like to populate every other entry of F with f, and return F as a function handle that converts to a double array when substituted for t. All other entries in the array should be zero. I thought what I have above would work, but that is not the case. Where am I going wrong here?
y = f(t)and then returns an array that alternates 0 andy. Does this need to be an anonymous function or can you write a regular function? (Note that you can have a handle to any type of function!)t