I'm new to matlab and this is one of the very first functions I wrote. My function works very well except that it's very slow (~27 seconds). How can I take advantage of Matlab's syntax to better optimize it?
function [ amin,bmin,cmin ] = perm( x,y,xmin )
A=(1:0.1:9);
B=(4:0.15:16);
C=(0.003:0.0005875:0.05);
result = 0.0;
amin = 15;
bmin = 16;
cmin = 0.05;
rmin = 1000;
temp = 0;
for i=1:81
for j=1:81 for k=1:81 result = -A(k)* erf((x-xmin)*C(i))+B(j); Error = minus(y,result).^2; temp = norm(Error); if temp < rmin; rmin = temp; amin = A(k); bmin = B(j); cmin = C(i); end end endend
end
Best Answer