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'));
|
1137 Solvers
Back to basics 9 - Indexed References
348 Solvers
187 Solvers
Make a random, non-repeating vector.
1115 Solvers
160 Solvers