Well, I made a silly mistake with the for loop. Should be for i=59:79. However, the condiiton for h_test>h_intercept still doesn't work
Help troubleshooting iteration code
1 view (last 30 days)
Show older comments
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 Comments
Andy L
on 11 Sep 2014
are you saying that the code should read
for i = 59:79
instead of
for j = 1:length(h_intercept)
Answers (2)
Image Analyst
on 11 Sep 2014
Here's a virtually foolproof way to solve it http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Guillaume
on 11 Sep 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 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!