Problem 44808. Make an anonymous function that has variable output

Solution 1685833

Submitted on 3 Dec 2018 by Peng Liu
  • Size: 8
  • This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
fid = fopen('anonymous.m'); st = regexprep(char(fread(fid)'), 'function', 'error(''No fancy functions!''); %','ignorecase',2); fclose(fid); fid = fopen('anonymous.m' , 'w'); fwrite(fid,st); fclose(fid);

2   Pass
f = anonymous; a = f(1); assert(a==1);

3   Pass
f = anonymous; a = f(1,2); assert(a==1); [a,b] = f(3,5); assert(a==3&b==5);

4   Pass
f = anonymous; a = f(1,2); assert(a==1); [a,b] = f(3,'56'); assert(a==3&isequal(b,'56'));

Suggested Problems

More from this Author17

Community Treasure Hunt

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

Start Hunting!