0

I have a 10 x 3 Matrix and would like to use each of the 10 rows as arguments to a function expecting 3 arguments using an iteration from 1 to 10. Problem is that I cannot pass each row vector directly into the function expecting 3 arguments. How can I convert the matrix rows to a format acceptable by my function?

Here is the function:

XXX = obj(Kc, T1, T2);

Calling code:

for i = 1:100                               
    pop(i,1) = 50 - rand*(50-1);
    pop(i,2) = 1 - rand*(1-0.1);
    pop(i,3) = 0.2 - rand*(0.2-0.01); 
    Kc(i) = pop(i,1); 
    T1(i) = pop(i,2); 
    T2(i) = pop(i,3); 

end

for j = 1:10
    kk = randperm(100);
    Tour1 = pop(kk(1:10),:);
    ZET(j) = obj(Tour1(j,:));

end

Tour1 is the 10 x 3 matrix whose rows need to become Kc, T1, T2. Thanks.

1
  • 2
    Why not Zet(j) = obj(Tour1(j,1),Tour1(j,2),Tour1(j,3));? Commented Oct 4, 2013 at 19:09

1 Answer 1

1

Convert to a cell array:

for j = 1:10
    kk = randperm(100);
    Tour1 = pop(kk(1:10),:);
    temp = mat2cell(Tour1(j,:),1,ones(1,numel(Tour1(j,:))))
    ZET(j) = obj(temp{:});
end
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks guys, you are far too kind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.