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

3 views (last 30 days)
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 ?

Answers (1)

Matt J
Matt J on 15 Nov 2013
Edited: Matt J on 15 Nov 2013
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 Comment
Ionut
Ionut on 15 Nov 2013
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.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!