How to Filter Array Based on Values in a Different Array?
38 views (last 30 days)
Show older comments
I have 3 arrays of the same dimensions, and the same indices in these arrays correspond to the same individuals. One array gives the geographic location in latitude of each individual where each row is an individual and each column is a time step and then it gives the latitude at each time step. The 2nd array is the same thing but with longitude. My final array works similarly to give the status of each individual (alive, dead, etc), with the rows representing the same individuals and the columns representing the same time steps and then a numeric value at each index representing the status (-3, -2, -1, 0, or 1).
I want to pull out the locations of certain individuals with a particular status, so I need to pull out all the x and y coordinates from my other 2 arrays based on what number is in the corresponding index of the status array. So for example make new arrays that contain all the x and y coordinates of all alive individuals with status 1, or even better one new array that provides the x and y together for each individual. I have no idea how to even begin this if anyone could point me in the right direction.
0 Comments
Accepted Answer
Voss
on 19 Jul 2022
% some random lat/lon/stat matrices
lat = randi([-90 90],5,10)
lon = randi([-180 180],5,10)
stat = randi([-3 1],5,10)
% get the lat and lon where stat == -2
idx = stat == -2;
lat_lon = [lat(idx) lon(idx)]
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing 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!