Execution time of functions used in anonymous function creation
Show older comments
Hello,
What is the best way to force immediate execution of a function that is being used as part of an anoymous function? Do you have to evaluate it in a previous line or can you somehow evaluate it at the same time as defining ?
Here's a simple example:
rng(0)
randomNum = @() rand
defines a very different function than
rng(0)
currentRandom = rand
randomNum = @() currentRandom
Is there a way to get the behavior of the second example with only two lines?
Or here's another more meaningful example:
% Capture current stack
currentStack = dbstack
stackAnalyzer = @(x) stackAnalysisFunction(x,currentStack)
defines a very different function than the much cleaner looking:
% Capture current stack
stackAnalyzer = @(x) stackAnalysisFunction(x,dbstack)
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!