FINDTRANSECTS Identify transects from waypoint coordinates. Syntax: TRANSECT_INDEX = FINDTRANSECTS(WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE) Description: TRANSECT_INDEX = FINDTRANSECTS(WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE) identifies transects (travels from one waypoint to the next one) from waypoint coordinates in vectors WAYPOINT_LATITUDE and WAIPONT_LONGITUDE, and flags each point with the index of the transect the point belongs to, starting from 1. WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE and TRANSECT_INDEX have the same length. Notes: A new transect starts whenever a change in latitude or longitude waypoint coordinate is found. Transects are numbered cumulating changes of latitude or longitude coordinates, ignoring invalid values (NaN) in the sequences. This function is based on the previous work by Tomeu Garau, in a function called GETTRANSECTS. He is the true glider man. Examples: waypoint_latitude = [39.50 nan 39.50 nan 39.21 nan 39.23 nan nan nan 38.98 nan 38.98] waypoint_longitude = [ 2.18 nan nan nan 1.65 nan 1.28 nan 1.09 nan 1.09 nan 0.12] transect_index = findTransects(waypoint_latitude, waypoint_longitude) figure subplot(2,1,1) plotyy(waypoint_latitude, 'og', waypoint_longitude, 'or') subplot(2,1,2) stairs(transect_index) Authors: Joan Pau Beltran <joanpau.beltran@socib.cat>
0001 function transect_index = findTransects(waypoint_latitude, waypoint_longitude) 0002 %FINDTRANSECTS Identify transects from waypoint coordinates. 0003 % 0004 % Syntax: 0005 % TRANSECT_INDEX = FINDTRANSECTS(WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE) 0006 % 0007 % Description: 0008 % TRANSECT_INDEX = FINDTRANSECTS(WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE) 0009 % identifies transects (travels from one waypoint to the next one) from 0010 % waypoint coordinates in vectors WAYPOINT_LATITUDE and WAIPONT_LONGITUDE, 0011 % and flags each point with the index of the transect the point belongs to, 0012 % starting from 1. WAYPOINT_LATITUDE, WAYPOINT_LONGITUDE and TRANSECT_INDEX 0013 % have the same length. 0014 % 0015 % Notes: 0016 % A new transect starts whenever a change in latitude or longitude waypoint 0017 % coordinate is found. Transects are numbered cumulating changes of latitude 0018 % or longitude coordinates, ignoring invalid values (NaN) in the sequences. 0019 % 0020 % This function is based on the previous work by Tomeu Garau, in a function 0021 % called GETTRANSECTS. He is the true glider man. 0022 % 0023 % Examples: 0024 % waypoint_latitude = [39.50 nan 39.50 nan 39.21 nan 39.23 nan nan nan 38.98 nan 38.98] 0025 % waypoint_longitude = [ 2.18 nan nan nan 1.65 nan 1.28 nan 1.09 nan 1.09 nan 0.12] 0026 % transect_index = findTransects(waypoint_latitude, waypoint_longitude) 0027 % figure 0028 % subplot(2,1,1) 0029 % plotyy(waypoint_latitude, 'og', waypoint_longitude, 'or') 0030 % subplot(2,1,2) 0031 % stairs(transect_index) 0032 % 0033 % Authors: 0034 % Joan Pau Beltran <joanpau.beltran@socib.cat> 0035 0036 % Copyright (C) 2013-2016 0037 % ICTS SOCIB - Servei d'observacio i prediccio costaner de les Illes Balears 0038 % <http://www.socib.es> 0039 % 0040 % This program is free software: you can redistribute it and/or modify 0041 % it under the terms of the GNU General Public License as published by 0042 % the Free Software Foundation, either version 3 of the License, or 0043 % (at your option) any later version. 0044 % 0045 % This program is distributed in the hope that it will be useful, 0046 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0047 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0048 % GNU General Public License for more details. 0049 % 0050 % You should have received a copy of the GNU General Public License 0051 % along with this program. If not, see <http://www.gnu.org/licenses/>. 0052 0053 error(nargchk(2, 2, nargin, 'struct')); 0054 0055 waypoint_coordinates = [waypoint_latitude(:) waypoint_longitude(:)]; 0056 0057 % Initialize transect index to have the same dimensions as given inputs. 0058 % This also handles degenerated cases (empty or all data invalid). 0059 transect_index = ones(size(waypoint_latitude)); 0060 if ~isempty(waypoint_coordinates) 0061 waypoint_coordinate_change = false(size(waypoint_coordinates)); 0062 for i = 1:2 0063 coord_valid_sel = ~isnan(waypoint_coordinates(:,i)); 0064 coord_valid_ind = find(coord_valid_sel); 0065 coord_valid = waypoint_coordinates(coord_valid_sel, i); 0066 coord_valid_change = [false; (coord_valid(2:end) ~= coord_valid(1:end-1))]; 0067 waypoint_coordinate_change(coord_valid_ind(coord_valid_change), i) = true; 0068 end 0069 transect_index(:) = 1 + cumsum(any(waypoint_coordinate_change, 2)); 0070 end 0071 0072 end