As mentioned in the comments : The execution of this line of insanity , and you are much better off using a separate function / .m file.
It will be
- Faster
- Easier to read
- Easier to write
- Easier to debug
You can do this, for example, similarly to this:
function out = R2TComputation(DL1, DL2, minLim, maxLim, C1) ...%Compute whatever R2T would compute.
To get the same interface as the original anonymous function, you can simply create
R2T = @(DL1, DL2) R2TComputation(DL1, DL2, minLim, maxLim, C1)
which will record the current values โโof minLim , maxLim and C1 during the creation of this R2T descriptor.
Another option would be to use a nested function instead of an external one. He will have access to the parent variables of the function, but can still use if , else and all the other basic tools you need. The only drawback: it is not intended to be accessed from other files.
... % Main function stuff function out = R2T(DL1, DL2) if ... out = ... ... end ... % Use R2T ...
However, for the sake of freedom to shoot in the foot, here is the built-in version of if-else , which I wrote in the spirit of Loren and I do not recommend using it , since it is hardly possible to use one expression instead of the corresponding if - else .
ifelse = @(cond, varargin) varargin{1+~cond}(); %Only for the insane
If you want a lazy rating , you need to pass an anonymous function with null parameters, which ifelse will then evaluate (which is for the last two parentheses () in ifelse ):
ifelse(true, 42, @()disp('OMG! WTF! THIS IS CRAZY!!111'))
If you simply wrote a call to the disp function as an ifelse argument without @() , the function is called before we even get access to ifelse . This is because MATLAB (like most other languages) first calculates the return value of the function, which is then passed to ifelse as a parameter.
In your case, the resulting code will look like this:
R2T = @(DL1,DL2) arrayfun(@(DL1,DL2)... ifelse(~any(isnan([DL1, DL2])), ... @() 1/(fzero(@(x)fFitObj1(x)./fFitObj2(x)-DL1./DL2,LIM)), ... NaN), ... DL1, DL2) - C1;