1

Right now I am creating mapstructs in Matlab and then exporting them individually as shape files using the shapewrite() function.

However, instead of exporting them individually I want to store all of them into an array and then save it at the end as one single shapefile which holds all of the points from the mapstructs stored in the array.

My problem is I don't know how to initialize an array to hold these mapstructs. I've tried

`a = struct(sizeofarray)`

but it isn't compatible with mapstructs. I would appreciate any help!

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Aaron
  • 1,693
  • 4
  • 26
  • 40
  • I have no experience in `mapstruct`, but this could be helpful (building array of structures): http://stackoverflow.com/questions/4166438/how-do-i-define-a-structure-in-matlab/4169216#4169216 – Amro Jul 21 '11 at 20:05

2 Answers2

2

You can store any kind of data in a cell array:

a = cell(sizeofarray,1);

You can then assign them like this:

a{1} = firstmapstruct;
a{2} = secondmapstruct;

However, if I understand you correctly you have mapstructs from the MATLAB Mapping Toolbox and want to concat structs of this form:

firstmapstruct = 
609x1 struct array with fields:
    Geometry
    BoundingBox
    X
    Y
    STREETNAME
    RT_NUMBER
    CLASS
    ADMIN_TYPE
    LENGTH

So you should probably do

a = firstmapstruct; 
a(end+1:end+numel(secondmapstruct))= secondmapstruct; 

and so on...

Jonas Heidelberg
  • 4,984
  • 1
  • 27
  • 41
1

If all of your individual mapstructs have the same fields, you should be able to initialize a structure array by replicating one of your mapstructs using the function REPMAT:

a = repmat(mapstruct1,1,N);  %# A 1-by-N structure array

Then just fill in each element as needed:

a(2) = mapstruct2;  %# Assign another mapstruct to the second array element
a(3).X = ...;       %# Assign a value to the X field of the third element
a(3).Y = ...;       %# Assign a value to the Y field of the third element

You can find out more information about Geographic Data Structures in this documentation.

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • If I could select two answers to my question, I would (I selected the other guy b/c he posted first and his was the implementation I eventually used). This technique also works for my case since they all have the same format though. Thanks again! – Aaron Jul 21 '11 at 20:19