Cody

# Problem 44808. Make an anonymous function that has variable output

Solution 2082706

Submitted on 7 Jan 2020
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);

f = function_handle with value: @(x)num2cell(x) y = function_handle with value: @(x)g(f(x))

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

f = function_handle with value: @(x)num2cell(x) y = function_handle with value: @(x)g(f(x))

Error using anonymous>@(x)g(f(x)) Too many input arguments. Error in Test3 (line 2) a = f(1,2);

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

f = function_handle with value: @(x)num2cell(x) y = function_handle with value: @(x)g(f(x))

Error using anonymous>@(x)g(f(x)) Too many input arguments. Error in Test4 (line 2) a = f(1,2);