Use a for loop to find out if point B is away from point A by a known amount
Afficher commentaires plus anciens
I have point A and point B. (In the figure only two pairs of A and B.)

condition: I want to find out if point B is far from point A by an amount between -2 and 2 in the X and Y direction (the -2 and 2 are included).
I need to create a for loop for all points (all rows) of the "sortedmat" matrix so that:
- if the condition is verified, I have to redo the loop.
- if the condition is not verified, I have to save the array with the points that were within the two intervals.
I started in the following way but I don't know how to go about it.
sortedmat = importdata("sortedmat.txt");
positive_distance_X = 2;
negative_distance_X = -2;
positive_distance_Y = 2;
negative_distance_Y = -2;
row_used_A = 1;
% row_used_A = 309;
point_A_direction_X = sortedmat(row_used_A,1);
point_A_direction_Y = sortedmat(row_used_A,2);
row_used_B = row_used_A + 1;
point_B_direction_X = sortedmat(row_used_B,1);
point_B_direction_Y = sortedmat(row_used_B,2);
distance_X_direction = point_B_direction_X - point_A_direction_X; % must be between negative_distance_X & positive_distance_X
distance_Y_direction = point_B_direction_Y - point_A_direction_Y; % must be between negative_distance_Y & positive_distance_Y
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
