how to use multiple 'for loop' for one function?
Show older comments
intersection_point = [];
for i = 1:length(mean_trajectory_double)-1
for j = 1:length(RKSI_Arr_33R)
for k = 1:length(RKSI_Arr_33R.Latitude)
[I,check]=plane_line_intersect([mean_trajectory_double(i+1,1) mean_trajectory_double(i+1,2) NormalVectorsmean_trajectory_double(i+1,3)]...
,[mean_trajectory_double(i+1,1) mean_trajectory_double(i+1,2) mean_trajectory_double(i+1,3)]...
,[RKSI_Arr_33R(j).Longitude(k) RKSI_Arr_33R(j).Latitude(k) RKSI_Arr_33R(j).BAlt(k)]...
,[RKSI_Arr_33R(j).Longitude(k+1) RKSI_Arr_33R(j).Latitude(k+1) RKSI_Arr_33R(j).BAlt(k+1)]);
intersection_point = [intersection_point; ];
end
end
end
%% [I,check]=plane_line_intersect(n,V0,P0,P1)
I need to use multiple for loop for one function. I have used multiple for loop, but i have not used multiple for loop for one function.
this function need 4 input and 2 output(I,check). I is intersection_point and check is an indicator.
for more information about this function, https://kr.mathworks.com/matlabcentral/fileexchange/17751-straight-line-and-plane-intersection
What i want to do is that
when i is 1, j is 1 and k(1~100) is finished, it goes to i(1), j(2),k(1~100).
and j(1-200) is finisiehd, it goes to i(2),j(1),k(1~100) and i(2),j(2),k(1~100) like this.
if you need more clarification to answer my question, just tell me
Thanks.
7 Comments
Rik
on 24 Jun 2022
Your loop will do as you describe. However, you're overwriting the I and check variables every iteration, without storing them anywhere.
Sierra
on 24 Jun 2022
Kenneth Joseph Paul
on 24 Jun 2022
Edited: Kenneth Joseph Paul
on 24 Jun 2022
For storing the intersection point you need to do this
intersection_point = [intersection_point; I ];
Kenneth Joseph Paul
on 24 Jun 2022
Put a break point at
[I,check]=plane_line_intersect([mean_trajectory_double(i+1,1) mean_trajectory_......
And print each of the inputs to the function and make sure that the dimensions are right
Sierra
on 24 Jun 2022
Jan
on 24 Jun 2022
Kenneth means a "break point". Click in the bar on the left side in the editor. Then a red dot appears. Matlab stops at this point and you can check the varaibels used in this line.
The break command is something else.
Kenneth Joseph Paul
on 24 Jun 2022
You need to use a "break point". As you said a "break" teminates the loop. A "break point" is used to temporarily pause the execution of the code. You can follow the page linked below, if you are not familiar with "breakpoint"
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!