Function handling problem in loop
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory 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!