How to create iteratively a vector of handle functions?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi! I want to create iteratively a vector of handle functions, for example:
If i have a large sequence of functions (sin(x),x^2,x^3,...,x^5), how can i create the vector of handle functions f(x) such that:
f= @(x) [sin(x);...
x^2;...
x^3;...
...;...
x^5] ?
The functions are most complicated in my aplication and could be diferent depending on some conditions, i.e., the secound row could be x^2 or cos(x), that is the reason why this porcess must be iterative. By last, I will use fsolve therefore that it is not possible applying cells. Thanks a lot for your answer.
댓글 수: 0
답변 (1개)
Steven Lord
2021년 10월 4일
c = {@sin; @cos; @tan};
f1 = @(x) cellfun(@(fh) fh(x), c); % Assuming the outputs are all scalar
y1 = f1(pi/4)
f2 = @(x) cellfun(@(fh) fh(x), c, 'UniformOutput', false); % If the outputs are not scalar
y2 = f2(0:0.25:1)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!