I need to split a vector into values separated by comma to feed a handle_function

조회 수: 3 (최근 30일)
Ionut
Ionut 2013년 11월 15일
댓글: Ionut 2013년 11월 15일
Hi, I need a bit of help, I have a system of equations defined in a handle_function. The number of equations and unknowns can vary from n=3 to n=100.
such equation may be
KBC{i} = matlabFunction(Cr.*(eta(i)+h)+sum(B.*(sinh(J.*k*(eta(i)+h)))./cosh(J.*k.*h).*cos(J.*k.*x(i)))+Q) ;
This gets incorporated into a larger holder F = {KBC ; ..etc..; length};
the symbolic variables are B(j) (j=1:n), eta(i) (i=1:n+1) Cr Q k, the other variables are known.
I need to feed the handle function with the required input arguments, but since they vary, my wanted inputs are computed in a vector "X0". So going straight forward it lead me to a stupid ideea of:
F{i}{i}(X0)
but since you can't feed with a vector containing the input arguments I need to split so that
F{i}{i}(X0(1),..,X0(n))
I tried to use num2cell(X0) but the given separation is not accepted by the handle_function since the values have to be separated by comma.
Any ideea ?

답변 (1개)

Matt J
Matt J 2013년 11월 15일
편집: Matt J 2013년 11월 15일
One way,
X0cell=num2cell(X0);
F{i}{i}(X0cell{:})
Alternatively, you don't have to define your F{i}{i} to be a function of n-separate arguments. You could (and maybe should) write it as a function of a single vector argument X0. Compare:
function y=f1(x1,x2,x3)
x1+x2+x3;
function y=f2(X)
y=sum(X(1:3));
  댓글 수: 1
Ionut
Ionut 2013년 11월 15일
Thank you. The first option worked for me. The second way was not suitable for my case because my total number of variables and equations 2n+6 and their participation in the whole system was different a bit strange.
Thanks again.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by