How do I call a function? Error:

Example:
Script 1:
function y = experiment(a,b)
y = (a + b)/2
*This is the function I want to call.
---------------------
Script 2:
function x = stupid(experiment, a, b)
x = experiment(a,b);
*This is the script I want to call my function into.
Both are saved in the /bin path.
----------
Error I receive when running in command:
stupid(experiment,1,2) ??? Input argument "a" is undefined.
Error in ==> experiment at 3 y = (a + b)/2
No idea how to go from here. Help welcome :)

답변 (1개)

Walter Roberson
Walter Roberson 2012년 10월 31일

1 개 추천

stupid(@experiment, 1, 2)
Otherwise, your function "experiment" is being called when the arguments in
stupid(experiment,1,2)
are being gathered together prior to calling stupid() itself, with MATLAB expecting that experiment() will return something that is suitable for passing into the first argument that stupid() expects.

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2012년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by