MATLAB: Function handling problem in loop

functionloop

Dear Researcher.
Might be it will be a silly question for you but i am stuck at this point . I have a two function which calulates minimum and max values as given below:
function out=fns1(X)
x1=X(:,1);
x2=X(:,2);
x3=X(:,3);
x4=X(:,4);
x5=X(:,5);
x6=X(:,6);
x7=X(:,7);
x8=X(:,8);
x9=X(:,9);
x10=X(:,10);
out = 5.16.*x1+5.12.*x2+4.89.*x3+4.79.*x4+4.99.*x5+5.45.*x6+4.65.*x7+4.99.*x8+5.45.*x9+5.5.*x10+3;
and the other is :
function out= fns(X)
x1=X(:,1);
x2=X(:,2);
x3=X(:,3);
x4=X(:,4);
x5=X(:,5);
x6=X(:,6);
x7=X(:,7);
x8=X(:,8);
x9=X(:,9);
x10=X(:,10);
fx =5.16.*x1+5.12.*x2+4.89.*x3+4.79.*x4+4.99.*x5+5.45.*x6+4.65.*x7+4.99.*x8+5.45.*x9+5.5.*x10+3;
for i=1:size(fx,1)
if fx(i,:)>=0
fit(i,:)=1./(1+fx(i,:));
elseif fx(i,:)<0
fit(i,:)=1+abs(fx(i,:));
end
end
out=fit;
I want to use function with different values of x1 x2 to x10. These values have in text form i want to know how i can get these values and use them in function for each iteraion just like that
for i=1:100
function out=fns1(X)
x1(i)=X(:,1);
x2(i)=X(:,2);
x3(i)=X(:,3);
x4(i)=X(:,4);
x5(i)=X(:,5);
x6(i)=X(:,6);
x7(i)=X(:,7);
x8(i)=X(:,8);
x9(i)=X(:,9);
x10(i)=X(:,10);
out (i)= 5.16.*x1+5.12.*x2+4.89.*x3+4.79.*x4+4.99.*x5+5.45.*x6+4.65.*x7+4.99.*x8+5.45.*x9+5.5.*x10+3;
help me out plz.
Thans in advance

Best Answer

Try
doc str2num
to convert from text to numeric.
Also, you might find it easier to define:
k = [5.16 5.12 4.89 4.79 4.99 5.45 4.65 4.99 5.45 5.5]';
and then calculate
fx = X*k+3;
etc.