From: Jonathan on
G'day,

I have the following code...

A = [1,2,3,4,]; %%%% DATA %%%%
lon = [-123.412482300000, -123.349197000000, -123.387645500000,-123.499196100000];
lat = [48.1177411000000,48.1170438000000,48.1850616000000,48.2661300000000];
N = length(A);

[test2(1:N).Geometry] = deal('Point'); %%%%% Create Structure %%%%%
for j = 1:N;
test2(j).Lon = lon(j);
test2(j).Lat = lat(j);
test2(j).id = A(j);
end

Is there a way I can speed up the process of creating the structure? In this example there are only four matrices that are integrated into the structure. However, I would like to do this for a 10*1000000+ data file. Using the above code, it took about 30 mins to do the first 200,000 lines of data.

Thanks
Jon
From: Matt J on
"Jonathan" <jkakiwi(a)yahoo.co.uk> wrote in message <hnc2mo$qp3$1(a)fred.mathworks.com>...

> Is there a way I can speed up the process of creating the structure? In this example there are only four matrices that are integrated into the structure. However, I would like to do this for a 10*1000000+ data file. Using the above code, it took about 30 mins to do the first 200,000 lines of data.
=====================

It's a really bad idea to split the data into structure elements this way, particularly in these large amounts. You're killing all of the memory contiguity that makes working with the data easy. I recommend that you work with the data in their original arrays.
From: TideMan on
On Mar 12, 4:00 pm, "Matt J " <mattjacREM...(a)THISieee.spam> wrote:
> "Jonathan" <jkak...(a)yahoo.co.uk> wrote in message <hnc2mo$qp...(a)fred.mathworks.com>...
> > Is there a way I can speed up the process of creating the structure?  In this example there are only four matrices that are integrated into the structure. However, I would like to do this for a 10*1000000+ data file.  Using the above code, it took about 30 mins to do the first 200,000 lines of data.
>
> =====================
>
> It's a really bad idea to split the data into structure elements this way, particularly in these large amounts. You're killing all of the memory contiguity that makes working with the data easy. I recommend that you work with the data in their original arrays.

I agree with Matt.
What are you trying to achieve here?
The only time I would use a structure array in this way is if I had
many different geometries, all with different numbers of components.
For geometry 1 you would read in the data and do:
test2(1).lon=lon; % this inserts the whole lon vector
test2(1).lat=lat;
test2(1).id=A;
Then for geometry 2 you would read in the data and do:
test2(2).lon=lon;
test2(2).lat=lat;
test2(2).id=A;
etc
etc
From: Jonathan on
I appreciate both your responses and you are exactly write. However, it appears to be the only way I can see how to create a geostructure (basically a GIS structure file) that can be converted by 'shapewrite - Mapping tooldbox' as a GIS shape file. I was able to create a single structure for the complete dataset but when using the shapewrite toolbox, the program produces an error. Hence, the need to create seperate geometry structures, which seems silly. I have contacted Matlab directly to see if they have any advice, but no luck so far. Again thanks for the input.

Jon

TideMan <mulgor(a)gmail.com> wrote in message <d25acd9a-c374-4115-939c-3c93aa395d0b(a)t17g2000prg.googlegroups.com>...
> On Mar 12, 4:00 pm, "Matt J " <mattjacREM...(a)THISieee.spam> wrote:
> > "Jonathan" <jkak...(a)yahoo.co.uk> wrote in message <hnc2mo$qp...(a)fred.mathworks.com>...
> > > Is there a way I can speed up the process of creating the structure?  In this example there are only four matrices that are integrated into the structure. However, I would like to do this for a 10*1000000+ data file.  Using the above code, it took about 30 mins to do the first 200,000 lines of data.
> >
> > =====================
> >
> > It's a really bad idea to split the data into structure elements this way, particularly in these large amounts. You're killing all of the memory contiguity that makes working with the data easy. I recommend that you work with the data in their original arrays.
>
> I agree with Matt.
> What are you trying to achieve here?
> The only time I would use a structure array in this way is if I had
> many different geometries, all with different numbers of components.
> For geometry 1 you would read in the data and do:
> test2(1).lon=lon; % this inserts the whole lon vector
> test2(1).lat=lat;
> test2(1).id=A;
> Then for geometry 2 you would read in the data and do:
> test2(2).lon=lon;
> test2(2).lat=lat;
> test2(2).id=A;
> etc
> etc
From: Jan Simon on
Dear Jonathan!

> A = [1,2,3,4,]; %%%% DATA %%%%
> lon = [-123.412482300000, -123.349197000000, -123.387645500000,-123.499196100000];
> lat = [48.1177411000000,48.1170438000000,48.1850616000000,48.2661300000000];
> N = length(A);
>
> [test2(1:N).Geometry] = deal('Point'); %%%%% Create Structure %%%%%
> for j = 1:N;
> test2(j).Lon = lon(j);
> test2(j).Lat = lat(j);
> test2(j).id = A(j);
> end
>
> Is there a way I can speed up the process of creating the structure? In this example there are only four matrices that are integrated into the structure. However, I would like to do this for a 10*1000000+ data file. Using the above code, it took about 30 mins to do the first 200,000 lines of data.

"The first 200,000 lines of data"? So you are reading from a file? This is not shown in the code snippet. Are you sure that the assigning to the struct is the bottleneck?

Jan