我想编写一个过滤数组的函数,最好是匿名函数.用文字说话很难,但是就像这样:
f = @(x) { if (x > 1) x+1 };
a = [ 1, 2, 3];
f(a) %
==> [ 1 3 4]
Run Code Online (Sandbox Code Playgroud)
我想要的关键点是:
这类似于函数log()的工作方式:
>> log(1)
ans =
0
>> log([1,2,3])
ans =
0 0.6931 1.0986
Run Code Online (Sandbox Code Playgroud)
谢谢