Create a function handle sum of other function

Hello everybody,
I try to create a function as sum of other functions, using data vectors of different size inside.
p = [0.1; 0.2; 0.3; 0.4] % p(i) is the weight associate
I get the from a Database a 4 x 6 parameter Matrix
C = [Data_11 Data_12 Data_13 Data_14 Data_15 Data_16
...
Data_41 Data_42 Data_43 Data_44 Data_45 Data_46];
I'm using an external function : func_ext(x, C_par)
— x is a scalar
— C_Par a 1x6 vector
I would like to create the following function handle as an inline function :
, where A is a constant
Do you have an idea ?
Thanks for help.

2 件のコメント

Stephen23
Stephen23 2022 年 1 月 14 日
It looks like the core of that is actually a basic matrix multiplication.
When you write that you " to create the following function" do you mean a function in the MATLAB sense (e.g. a function handle) or just an array of values?
Pascal Denis
Pascal Denis 2022 年 1 月 14 日
I'm mean function Handle not an array of values

サインインしてコメントする。

 採用された回答

Rik
Rik 2022 年 1 月 14 日

0 投票

Your anonymous function will become more opaque and I expect the performance to suffer, but this will work:
fun=@(x) A;
for i=1:size(p,1)
fun=@(x) fun(x) + ...
p(i)*func_ext(x,C(i,:));
end
Although I would suggest using a different loop variable than i. You have the entire alphabet, so why use something that could be confused with sqrt(-1).

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 1 月 14 日

コメント済み:

2022 年 1 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by