필터 지우기
필터 지우기

Help troubleshooting iteration code

조회 수: 3 (최근 30일)
Buzz
Buzz 2014년 9월 11일
댓글: Buzz 2014년 9월 11일
Hi,
I have an iteration code which I am using to find latitude/longitude of a set of heights (h_intercept). This is a 1x79 matrix.
It works perfectly until the 22nd value. I've found that this is when h_test>h_intercept. I tried to put a condition in to reset it but it doesn't work.
Furthermore, the strange thing is that the iteration runs and finds the height - the issue is that it is taking the wrong height.
For example
h_intercept=sat_look_pass1_llh(3,60:79)/2e3;
for j=1:length(h_intercept)
rng_sat= sat_look_tcs_pass1(3,j);
u_sat=[sat_look_tcs_pass1(1,j)/sat_look_tcs_pass1(3,j);sat_look_tcs_pass1(2,j)/sat_look_tcs_pass1(3,j);sat_look_tcs_pass1(3,j)/sat_look_tcs_pass1(3,j)];
h_intercept=sat_look_pass1_llh(3,j)/2e3;
h_test=zeros(1,3);
rng_test_min=0;
rng_test_max=rng_sat/2e3;
err=0.01;
while abs(h_intercept-h_test)>err
rng_test=(rng_test_min+rng_test_max)/2;
tcs_test=u_sat*rng_test;
llh_test=tcs2llhT(tcs_test,station_llh);
h_test=llh_test(3,:);
if h_test>=h_intercept
rng_test_max=rng_test;
else
rng_test_min=rng_test;
end
end copter_llh(:,j)=(llh_test); h_interceptloop(:,j)=(h_intercept); end % code end
This code is using values 60:79 of my matrix and although it runs, it is actually finding h_intercept(1,1:19)
It seems that after h_test>h_intercept, it starts from the beginning of the height matrix. How is that possible?!
Any suggestions appreciated!
  댓글 수: 3
Andy L
Andy L 2014년 9월 11일
are you saying that the code should read
for i = 59:79
instead of
for j = 1:length(h_intercept)
Buzz
Buzz 2014년 9월 11일
Yeah, I realise that it was giving the wrong height because I had for j=1:length(h_intercept). So it does work for h_test<h_intercept but not when it is more

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

답변 (2개)

Image Analyst
Image Analyst 2014년 9월 11일
Here's a virtually foolproof way to solve it http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/

Guillaume
Guillaume 2014년 9월 11일
You start with this line:
h_intercept=sat_look_pass1_llh(3,60:79)/2e3;
which as you say uses columns 60 to 79 of your sat_look_pass1_llh matrix. However, in the for loop, you overwrite it with:
h_intercept=sat_look_pass1_llh(3,j)/2e3;
with j from 1 to 19 (length(h_intercept)). Thus you're iterating over columns 1 to 19. As it is the first line serves no purpose.
I suspect you wanted to do:
h_intercepts=sat_look_pass1_llh(3,60:79)/2e3;
for j = 1:length(h_intercepts)
h_intercept = h_intercepts(j);
...
end
which you could also simplify with
h_intercepts=sat_look_pass1_llh(3,60:79)/2e3;
for h_intercept = h_intercepts
...
end
  댓글 수: 4
Buzz
Buzz 2014년 9월 11일
h_test=zeros(1,3) doesn't change anything. I was testing it out and can just be h_test=0, as an initial condition. Yeah, I stepped through it and I know that the values that don't work are greater than h_test (474m). I know that my if condition is not working, as it should step back
Buzz
Buzz 2014년 9월 11일
when h_test>h_intercept, all range values become zero

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by