Convert the variables x1, x2,... in an anonymous function to x(1,:) ,x(2,:).....
Show older comments
For example: f = @(x1, x2, ... , x15) x1 .* x2 .* ... .* x15
I want get: f = @(x) x(1,:) .* x(2,:) .* ... .*x(15,:)
Answers (2)
Andrei Bobrov
on 28 Mar 2013
Edited: Andrei Bobrov
on 28 Mar 2013
x = randi([-5 5],2,10); % this is your data
xc = num2cell(xc,2);
out = f(xc{:});
2 Comments
Matt J
on 28 Mar 2013
I think this should be
xc = num2cell(xc,2);
Andrei Bobrov
on 28 Mar 2013
Thank you Matt! Corrected.
Azzi Abdelmalek
on 28 Mar 2013
f=@(x) prod(x)
4 Comments
chen
on 28 Mar 2013
Azzi Abdelmalek
on 28 Mar 2013
Edited: Azzi Abdelmalek
on 28 Mar 2013
If your function is different then change it. t's not clear for me what you want
chen
on 28 Mar 2013
Azzi Abdelmalek
on 28 Mar 2013
You can't do conversion
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!