Applying a Function to Every Element of a List

I have a function taking 2 input values, say f(x,y) and a list, say L=[L1 L2 ... Ln]
How can I get the list L'=[f(L1,a) f(L2,a) ... f(L3,a)] where a is just a constant?
Thanks

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 24일
편집: Azzi Abdelmalek 2013년 2월 24일

0 개 추천

arrayfun(@(x) f(x,a),L,'un',0)
read
doc arrayfun
doc cellfun
Example
L=randi(10,1,10)
out=arrayfun(@(x) max(x,5),L)
Andrei Bobrov
Andrei Bobrov 2013년 2월 25일

0 개 추천

f2 = @(x,y)bsxfun(str2func(vectorize(func2str(f))),x,y.');
out = f2(1:4,2:4); % example

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

태그

질문:

2013년 2월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by