function handle specify in matlabfcn function

Hi,
Is it possible to specify the function handle in matlabfcn function when using the spreadsheet link in Excel? when i try to do an integration with the syntax"=@matlabfcn("quadgk","@(x) x.^2",M3,M4)" in Excel, it returnd an error, and said the first input argument must be function handle, is there anyone can help me how to specify the function handle in matlabfcn function? Many thanks.

回答 (1 件)

Jan
Jan 2021 年 11 月 14 日
編集済み: Jan 2021 年 11 月 16 日

0 投票

According to the documentation doc matlabfcn :
=matlabfcn("quadgk(@(x) x.^2)", M3, M4)

7 件のコメント

llu
llu 2021 年 11 月 16 日
Thanks for your help @Jan, but it still does not work, is it workable in your Excel?
Jan
Jan 2021 年 11 月 16 日
quadgk needs 3 input arguments: A function and the initial and final limit. It is not clear how you try to provide the function in the Excel call. So please post, what the inputs are, what you want to calculate and what "does not work" means.
llu
llu 2021 年 11 月 20 日
Hi Jan, I'd like to use matlab function from excel to calculate the numerical integration, below is the screenshot
Jan
Jan 2021 年 11 月 20 日
Matlab's quadgk command requires 3 inputs: The function handle and 2 limits. You call it with 1 input only.
llu
llu 2021 年 11 月 21 日
Syntax "matlabfcn("quadgk(@(x) x.^2,1,2)")" can work, but i want to pass the 2 limits from Excel as arguments.
Jan
Jan 2021 年 11 月 21 日
編集済み: Jan 2021 年 11 月 21 日
I cannot test it by my own. What about:
matlabfcn("@(a,b) quadgk(@(x) x.^2,a, b)", L3, L4)
llu
llu 2021 年 11 月 22 日
Can't work. Currently, the only methodology that I find is using the user definded function, like below:
function y = ab(a,b)
f= @(x) x.^2;
y= quadgk(f,a,b);
end
then use the syntax " matlabfcn("ab",L3,L4)" in excel

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

質問済み:

llu
2021 年 11 月 14 日

コメント済み:

llu
2021 年 11 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by