WRITEPOLYGONSET Write a set of simple polygons into a file. writePolygonSet(POLYS, FILENAME); Writes the set of polygons in the file FILENAME. Following format is used: X11 X12 X13 ... X1N Y11 Y12 Y13 ... Y1N X21 X22 X23 ... X2N Y21 Y22 Y23 ... Y2N Each polygon may have a different number of vertices. See also polygons2d, readPolygonSet
0001 function writePolygonSet(polys, filename) 0002 %WRITEPOLYGONSET Write a set of simple polygons into a file. 0003 % 0004 % writePolygonSet(POLYS, FILENAME); 0005 % Writes the set of polygons in the file FILENAME. 0006 % Following format is used: 0007 % X11 X12 X13 ... X1N 0008 % Y11 Y12 Y13 ... Y1N 0009 % X21 X22 X23 ... X2N 0010 % Y21 Y22 Y23 ... Y2N 0011 % Each polygon may have a different number of vertices. 0012 % 0013 % See also 0014 % polygons2d, readPolygonSet 0015 0016 % ------ 0017 % Author: David Legland 0018 % E-mail: david.legland@inrae.fr 0019 % Created: 2013-01-14 0020 % Copyright 2013-2024 INRA - TPV URPOI - BIA IMASTE 0021 0022 % open file for reading 0023 fid = fopen(filename, 'wt'); 0024 0025 for i = 1:length(polys) 0026 poly = polys{i}; 0027 n = size(poly, 1); 0028 0029 % precompute format 0030 format = [repmat('%g ', 1, n) '\n']; 0031 0032 % write one line for x, then one line for y 0033 fprintf(fid, format, poly(:,1)'); 0034 fprintf(fid, format, poly(:,2)'); 0035 end 0036 0037 % close file 0038 fclose(fid);