|
"Bernd Bum端ller" <leiwies@gmx.de> wrote in message
news:ho7nmm$qvh$1@fred.mathworks.com...
> "Jan Simon" wrote
>> It is always redommended not to claim "this does not work", but post the
>> exact error message and the corresponding line of code. Nobody can run
>> your code, so it is impossible to guess, what exactly happens.
>>
>> You could try this: Call your function SUM with a function handle:
>> someFunction(sum(@parameters2))
>> Then the "lalala" is not needed.
>> But it could be easier to apply your calling method and use VARARGIN to
>> handle a different number of inputs.
>>
>> BTW: Do not use the name of builtin functions as "sum" as names for
>> functions or variables. You can find a lot of postings here, which have
>> been solved by avoiding these names.
>>
>> Good luck, Jan
>
> Hallo Jan,
> great answer, it worked with varargin. But i am still interested in how it
> should look like with function handles. Your suggestion:
>
> [Code]
> function some=anyfun(function_handle)
> [a,b]=function_handle;
> some=a+b;
> [/Code]
> [Code]
> someFunction(anyfun(@parameters2))
> [/Code]
>
> brings the error message: anyfun.m, line 2, column 5
> "function_handle" was previously used as a variable,
> conflicting with its use here as the name of a function
>
> I would be happy about any new suggestions!
Bernd,
I _think_ I understand what you're trying to do, but if I'm wrong you should
start at the beginning and explain what exactly you're trying to accomplish.
Your original posting, when I reread it, sounds more like you have decided
upon an approach and want to know how to implement it, but there may be an
alternate approach that's easier to understand, more robust, and/or more
efficient.
If you want to invoke a function handle with 0 inputs, you need to call it
using empty parentheses:
function some = anyfun(function_handle)
[a, b] = function_handle();
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|