Wow...never thought this one also do the trick. Awesome!
Why does str2num work for anonymous function?
Don't be confused by the name "str2num", which might give you a wrong impression that this function only works for str to number conversion. In fact, it is more powerful because it supports evaluation of any valid string or character represented MATLAB expressions in much the same way eval does. The underlying implementation of str2num is indeed based on eval. Check the documentation and source file for more details.
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'));
|
276 Solvers
Back to basics 19 - character types
189 Solvers
Unique values without using UNIQUE function
115 Solvers
180 Solvers
Mirror Image matrix across anti-diagonal
86 Solvers