How to Filter Array Based on Values in a Different Array?
조회 수: 39 (최근 30일)
이전 댓글 표시
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
채택된 답변
Voss
2022년 7월 19일
% 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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!