How to input a vector into a multi variable function as individual components?

조회 수: 4 (최근 30일)
This top part will be the input of my function and this part cannot be manipulated.
F = @(x1,x2) [(4*x1^2 - 20*x1 + x2^2/4 + 8) ; (x1*x2/2 + 2*x1 - 5*x2 + 8)];
x0 = [0 ; 0];
What I want to do is evaluate the function at F(x0(1),x0(2)) (for this example) and have it output the solution. But to keep it general let's say
i = nargin(F)
for n = 1:i
F(x0(1),x0(2),x0(...),x0(n))
end
not real and it's definitely ghetto code but hopefully shows you what I'd like to do. I'm looking for a way to evaluate F composed of the individual components of x0 basically.
Also, x0 will always be a column vector with the length equal to the number of inputs in F.
The solution for what I want in the above example is: F(0,0) = [8 ; 8]
Hopefully this makes sense... Any advice would be greatly appreciated!

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 28일
xtemp = num2cell(x0);
F(xtemp{:})

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by