필터 지우기
필터 지우기

How can put the values inside tolerances?

조회 수: 1 (최근 30일)
theintern
theintern 2017년 10월 19일
댓글: KL 2017년 10월 20일
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
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
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
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
  댓글 수: 6
theintern
theintern 2017년 10월 20일
I am really appreciated @KL ! Thank you so much, I learned many things thanks to you.
KL
KL 2017년 10월 20일
You're very welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rik
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
  댓글 수: 1
theintern
theintern 2017년 10월 19일
I mean the fs1 value never go into tolerance.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by