Help troubleshooting iteration code

3 visualizzazioni (ultimi 30 giorni)
Buzz
Buzz il 11 Set 2014
Commentato: Buzz il 11 Set 2014
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 Commenti
Andy L
Andy L il 11 Set 2014
are you saying that the code should read
for i = 59:79
instead of
for j = 1:length(h_intercept)
Buzz
Buzz il 11 Set 2014
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

Accedi per commentare.

Risposte (2)

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

Guillaume
Guillaume il 11 Set 2014
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 Commenti
Buzz
Buzz il 11 Set 2014
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 il 11 Set 2014
when h_test>h_intercept, all range values become zero

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by