Convert the variables x1, x2,... in an anonymous function to x(1,:) ,x(2,:).....
이전 댓글 표시
For example: f = @(x1, x2, ... , x15) x1 .* x2 .* ... .* x15
I want get: f = @(x) x(1,:) .* x(2,:) .* ... .*x(15,:)
답변 (2개)
Andrei Bobrov
2013년 3월 28일
편집: Andrei Bobrov
2013년 3월 28일
x = randi([-5 5],2,10); % this is your data
xc = num2cell(xc,2);
out = f(xc{:});
댓글 수: 2
Matt J
2013년 3월 28일
I think this should be
xc = num2cell(xc,2);
Andrei Bobrov
2013년 3월 28일
Thank you Matt! Corrected.
Azzi Abdelmalek
2013년 3월 28일
f=@(x) prod(x)
댓글 수: 4
chen
2013년 3월 28일
Azzi Abdelmalek
2013년 3월 28일
편집: Azzi Abdelmalek
2013년 3월 28일
If your function is different then change it. t's not clear for me what you want
chen
2013년 3월 28일
Azzi Abdelmalek
2013년 3월 28일
You can't do conversion
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!