How can put the values inside tolerances?
1 次查看(过去 30 天)
显示 更早的评论
for i=1:length(As1)
[vq]=dd(Vs1,As1(i));
As = vq.*(Us(j).^2)./(16.*(pi.^2).*msksi.*fs1(j));
res1=As1(i)-As;
if abs(res1)<0.01
As1(i)=As;
Us(j)=Vs.*fs(j);
break
end
11 个评论
KL
2017-10-20
编辑:KL
2017-10-20
I have removed the equations and replaced them with dummy functions.
@theintern: No hard feelings, this is an open forum and we are all volunteers here just because we like what we do and to share the knowledge and learn together.
These things can happen, not to mention you'd have been stressed to finish your task before the deadline. You have posted your question with fairly decent descriptions (compared to homework questions which we see on daily basis) with whatever you've tried. But next time, if the code is not allowed to be posted online, try to emulate it as a minimal problem so we can understand your original situation and help you. Good luck!
Rik
2017-10-20
I agree with Jan and KL. Sweating it is never nice, so you should learn from it, which I think you did.
采纳的回答
KL
2017-10-19
编辑:KL
2017-10-20
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;
%load the data only once!!
m = load('myarray.mat');
myarray = m.myarray;
d = load('datas2.mat');
datas2 = d.datas2;
loop=0;
for i=1:length(As1)
%do it here, why repeat the very same thing 200 times everytime!
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
更多回答(1 个)
Rik
2017-10-19
What do you mean, it doesn't stop? These are for-loops, so they will exit. Do you mean you want to break out of both loops at the same time? If that is the case, the code structure below should help.
BreakLoop=false;
for i=1:length(As1)
if BreakLoop,break,end
for j=1:length(fs1)
...
if abs(res1)<0.01 && abs(res2)<0.01
BreakLoop=true;
break
end
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!