For loop causing an Infinite loop

I have a problem of infinite loop,please find attached three files of two different function and one text file. And find below what I'm trying to pass througth the two functions,( the problem happened at the last line below)
fid=fopen('elcentro.dat.txt.','r');
text=textscan(fid,'%f %f');
fclose(fid);
time=text{1,1};
dt=time(2)-time(1);
xgtt=text{1,2};
Tsoft=1560;
Tspectra=logspace(log10(0.02),log10(50),1560)';
ksi1=0;
ksi2=0.1;
ksi3=0.2;
u0=0;
ut0=0;
maxxgtt=max(abs(xgtt));
[~,~,~,maxxgt,~]=LERS(dt,xgtt,Tsoft,0)
[PSa1,PSv1,Sd1,Sv1,Sa1]=LERS(dt,xgtt,Tspectra,ksi1);

댓글 수: 4

Rik
Rik 2018년 11월 18일
Please don't delete a question and re-post it.
Although the code you've attached here is slightly different, I still notice NewmarksE doesn't use omegaj, so each iteration should still be the same. The mlint will have given you a warning inside that function.
I do not see any "for" loop in your code:
fid=fopen('elcentro.dat.txt.','r');
text=textscan(fid,'%f %f');
fclose(fid);
time=text{1,1};
dt=time(2)-time(1);
xgtt=text{1,2};
Tsoft=1560;
Tspectra=logspace(log10(0.02),log10(50),1560)';
ksi1=0;
ksi2=0.1;
ksi3=0.2;
u0=0;
ut0=0;
maxxgtt=max(abs(xgtt));
[~,~,~,maxxgt,~]=LERS(dt,xgtt,Tsoft,0)
[PSa1,PSv1,Sd1,Sv1,Sa1]=LERS(dt,xgtt,Tspectra,ksi1);
Where is it? The "last line" you referred to is a function call, not a for loop.
Stephan
Stephan 2018년 11월 18일
편집: Stephan 2018년 11월 18일
@Image Analyst: The former attached files were deleted by the OP during the last edit.
Guillaume
Guillaume 2018년 11월 18일
@Ahmad, why should we waste time trying to help you if you're going to close or delete every question that you ask?

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

답변 (1개)

Guillaume
Guillaume 2018년 11월 18일

0 개 추천

There are only two loops in your code, one with length(T) steps, one with numel(F)-1 steps. These values are guaranteed to be finite, thus your loops are guaranteed to finish eventually. If length(T) or numel(F) are very large and if the operations inside the loops are very slow, it could of course take a very long time.
The best way for you to understand what is happening is to debug your code. With the debugger, step through it one line at a time. Look at the result of each line and check that it conforms to your expectation. Most likely, you've made a mistake somewhere and some value is much larger than you expected.
If not, and your code work as expected then (and only then) profile your code to find out where it's slow.No point in profiling your code if it has bugs though.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2018년 11월 18일

댓글:

2018년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by