Map function in MATLAB?

前端 未结 7 826
情书的邮戳
情书的邮戳 2020-11-29 17:11

I\'m a little surprised that MATLAB doesn\'t have a Map function, so I hacked one together myself since it\'s something I can\'t live without. Is there a better version out

7条回答
  •  攒了一身酷
    2020-11-29 17:50

    You don't need map since a scalar-function that is applied to a list of values is applied to each of the values and hence works similar to map. Just try

    l = 1:10
    f = @(x) x + 1
    
    f(l)
    

    In your particular case, you could even write

    l.^2
    

提交回复
热议问题