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.
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