www.gusucode.com > map 案例源码 matlab代码程序 > map/AddNewValuesToExistingGeopointVectorExample.m

    %% Add New Values to Existing geopoint Vector
% This example shows how to add new values to an existing geopoint vector.
% The example appends data about Paderborn Germany to the geopoint vector
% of data about world cities.
%%
% Read world cities data using the |shaperead| command.  |shaperead|
% returns a structure array.

% Copyright 2015 The MathWorks, Inc.

structArray = shaperead('worldcities.shp', 'UseGeoCoords', true); 
%%
% Create a geopoint vector from the structure array. Display the last of
% the 318 elements in the vector.
p = geopoint(structArray);
p(end)	
%%
% Add the Paderborn data to the end of the geopoint vector. Display the
% last of the existing elements and the new element.
lat = 51.715254;		
lon = 8.75213;
p = append(p, lat, lon, 'Name', 'Paderborn');
p(end-1:end) 		
%%
% Another way to add a point at the end of a vector is to use linear
% indexing. For example, add data about Arlington, Massachusetts to the end
% of the world cities vector. Notice how, after the initial assignment
% statement appends a value to the Latitude property vector, using |end+1| ,
% all other property vectors automatically expand by one element. Display
% the last of the existing elements and the new element.
p(end+1).Latitude = 42.417060
p(end).Longitude = -71.170200;
p(end).Name = 'Arlington';	
p(end-1:end)