map() in matlab

来源:互联网 发布:windows快捷键 编辑:程序博客网 时间:2024/06/05 07:19

function results = map(f,list) 
% why doesn't MATLAB have a Map function? 
results = zeros(1,length(list)); 
for k = 1:length(list) 
    results(1,k) = f(list(k)); 
end 
 
end 

usage would be e.g.

map( @(x)x^2,1:10) 

原创粉丝点击