Insert multidimensional array into function handle
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm trying to solve a symbolic var from a function f(x,y), that should take pairs (x,y) as input.
However, MATLAB does not accept the array as input to a function handle to calculate them as a result array.
My code:
syms c
o = [ c 0 0; c 0 2; c 1 1; c 1 2; c 2 2; c 2 3; c 3 0; c 3 1; c 3 2; c 3 3 ]
f = @(c,x,y) c*(x+y)
eq = sum(arrayfun(f, o)) == 1 % ERROR FROM arrayfun() -> doesnt understand the multidim array input
solve(eq, c)
Gives this error:
"Not enough input arguments.
Error in @(c,x,y)c*(x+y)".
Thanks in advance!
0 件のコメント
採用された回答
Steven Lord
2021 年 3 月 23 日
syms c
o = [ c 0 0; c 0 2; c 1 1; c 1 2; c 2 2; c 2 3; c 3 0; c 3 1; c 3 2; c 3 3 ];
f = @(c,x,y) c.*(x+y); % Use element-wise multiplication
V = f(o(:, 1), o(:, 2), o(:, 3))
solve(sum(V) == 1, c)
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!