Firstly, you don't need those digdata, digdata2 functions. You're code is very slow because of them. You're loding the same mat files again and again for more than 40000 times. secondly, you should move those lines outside the inner loop, why do the same thing 201 times everytime?!.
So here's the cleaned up code, this is faster so it's much easier now to figure out what's your problem.
ms=1;
msksi=0.013;
Vs1=5.5;
As1=0.05:0.005:1.05;
fs1=0.5:0.005:1.5;
m = load('myarray.mat');
myarray = m.myarray;
d = load('datas2.mat');
datas2 = d.datas2;
loop=0;
for i=1:length(As1)
vq(i) = griddata(myarray(:,1),myarray(:,2),myarray(:,3),Vs1,As1(i));
vq2(i) = griddata(datas2(:,1),datas2(:,2),datas2(:,3),Vs1,As1(i));
for j=1:length(fs1)
Us(j)=Vs1.*fs1(j);
As(i,j) = func_find_As(vq(i),Us(j),mksi,fs1(j));
fs(i,j) = func_find_fs(vq2(i),Us(j),ms,As1(j));
[res1(i,j), res2(i,j)] = calculateRes(As(i,j),As1,fs(i,j),fs1);
[As1, fs1, Us] = checkTolerance(res1,res2);
end
loop=loop+1;
end
Best Answer