Reputation: 3208
so I'm trying to do some data processing in matlab, but i'm having issues with filtering out the data that I need.
So the data I have is in the format.
data1 = [time1, time2, time3, time4, time5, time...]
data2 = [d1, d2, d3, d4, d5, d....]
data3 = [latitude1, latitude2, latitude3, latitude4, latitude5, latitude....]
data4 = [longitude1, longitude2, longitude3, longitude4, longitude5, longitude...]
Whereas all the data in each column is related. And each row has the same number of elements.
What I want to do is filter out data that does not fit within a certain latitude and longitude.
So my thoughts are to turn these all into a matrix,
matrix1 =[data1;data2;data3;data4]
giving something like:
[ time1, time2, time3, ...]
| d1, d2, d3, ...|
| lat1, lat2, lat3, ...|
[ lng1, lng2, lng3, ...]
and then to write something that will delete a column if element in data3 and data4 don't meet the condition of being within this lat/lng boundary.
pseudo-code ie:
if(!data3.entry.isInRange(latrng1,latrng2) || !data4.entry.isInRange(lngrng1,lngrng2)){
deleteCurrentColumn;
}
So for example if lat2 or lng2 is out of bounds the matrix would then be transformed into:
[ time1, time3, ...]
| d1, d3, ...|
| lat1, lat3, ...|
[ lng1, lng3, ...]
How could I go about making something similar to the above pseudocode work in Matlab? My end goal is to organize/filter the matrix by location bounds.
Any help is appreciated! Thanks!
Upvotes: 1
Views: 170
Reputation: 16791
You would create a logical array of the columns that meet all of the criteria:
inRange = (data3 >= latrng1) & (data3 <= latrng2) &...
(data4 >= lngrgn1) & (data4 <= lngrng2);
Then use that as a column index into matrix1
:
filteredMatrix = matrix1(:, inRange);
Upvotes: 2