How to create function handle with matrix inputs, vector output?

1 回表示 (過去 30 日間)
ejk
ejk 2020 年 8 月 6 日
回答済み: madhan ravi 2020 年 8 月 6 日
I am trying to create a function:
FCN = @(x) x(1) + x(2);
that will accept matrix inputs and spit out a vector of values.
Ie. if the input is:
in=[1 2; 3 4], FCN(in)
the output should be: [3 7]
Is there any way of doing this? Right now, the function is only returning the sum of the first column.

採用された回答

madhan ravi
madhan ravi 2020 年 8 月 6 日
FCN = @(x) x(:, 1) + x(:, 2);
sum(in, 2) % ??

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by