Select data values from within a range
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I have a matrix of about 42000 rows, which give latitudes and longitudes of each entry in columns 7 and 8 respectively. Right now, my script pulls latitudes and longitudes as variables, and then another couple lines select values within a range. My script is below:
lat_r = A(:,7);
long_r = A(:,8);
lat = lat_r(lat_r > x & lat_r < y);
long = long_r(long_r > a & long_r < b);
My problem is that this only lists each value from each individual column that is between the given values (x,y or a,b). What I'd like to do is be able to find which rows have a latitude within the given range and then check if the corresponding longitude is also within the given range, then enter these values into a nx2 matrix.
This is probably a quick answer, but I'm fairly new working with MATLAB so any help would be greatly appreciated.
0 commentaires
Réponses (1)
Akshat
le 30 Jan 2025
The issue mentioned by you can be tackled using logical indexing, which is supported by MATLAB. In this, you basically get the indices where both the conditions are true.
Following I have modified your code to get the indices with both the conditions true.
lat_r = A(:, 7);
long_r = A(:, 8);
valid_indices = (lat_r > x & lat_r < y) & (long_r > a & long_r < b);
valid_lat_long = A(valid_indices, [7, 8]);
disp(valid_lat_long);
Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!