MATLAB: Hello guys, I need help.

function evaluated

I need to evaluate the function in each combination of (x1, x2, x3), that is:
for i=1:11
for j=1:11
for k=1:11
z(i,j,k)=feval(f,x1(i),x2(j),x3(k));
end
end
end
This evaluation gives us an NxNxN matrix (cell?). I don't know what it's called hahahaha
[sfx, ind]=sort(z(:));
we selected the t smallest function values
sfx=sfx(1:t);
And the indexes corresponding to the t smallest function values
ind=ind(1:t);
Does anyone have any idea how I can return the values of x1, x2 and x3 corresponding to these t smallest function values?

Best Answer

The indices you get in your last operation can be converted to subscripts, which will correspond to your three inputs.
ind=ind(1:t);
[x1_ind,x2_ind,x3_ind]=ind2sub(size(z),ind);
x1=x1(x1_ind);
x2=x1(x2_ind);
x3=x1(x3_ind);