1 | function [Mvalue Mx My]=CreateDataMatrix(x_m,y_m,track_coord,track_values),
|
---|
2 | %CREATEDATAMATRIX - Create a map with average values of map
|
---|
3 | %
|
---|
4 | % This routine creates a map with average values of tracks.
|
---|
5 | % x_m1 and y_m1 are two vectors containing the coordinates of the matrix
|
---|
6 | % trac_coord is an exp file containing the coordinates of the tracks (x and y)
|
---|
7 | % trav_values is a vector with the values along the track coordinates
|
---|
8 | %
|
---|
9 | % Usage:
|
---|
10 | % [Mvalue Mx My]=CreateDataMatrix(x_m,y_m,track_coord,track_values),
|
---|
11 | %
|
---|
12 | % Example:
|
---|
13 | % [Mvalue Mx My]=CreateDataMatrix(x_m,y_m,'trackcoord.exp',thickness_track)
|
---|
14 | %
|
---|
15 | % See also: CREATEDATABOUNDARIES, TRACKSTOMATRIX
|
---|
16 |
|
---|
17 | %Read the points of the tracks
|
---|
18 | stru=expread(track_coord,1);
|
---|
19 | nods=stru.nods;
|
---|
20 | xtracks=stru.x';
|
---|
21 | ytracks=stru.y';
|
---|
22 |
|
---|
23 | %First check that the parameters are ok:
|
---|
24 | if (size(track_values,1)~=nods) || (size(xtracks,2)~=nods) || (size(ytracks,2)~=nods),
|
---|
25 | error('CreateDataMatrix error message : track coordinates and track values must have the same size');
|
---|
26 | end
|
---|
27 |
|
---|
28 | %Compute number of rows and columns
|
---|
29 | numrow=size(y_m,1)-1;
|
---|
30 | numcol=size(x_m,1)-1;
|
---|
31 |
|
---|
32 | %Remove useless points of the track
|
---|
33 | points=find(track_values==0);
|
---|
34 | track_values(points)=[];
|
---|
35 | xtracks(points)=[];
|
---|
36 | ytracks(points)=[];
|
---|
37 | points=find(isnan(track_values));
|
---|
38 | track_values(points)=[];
|
---|
39 | xtracks(points)=[];
|
---|
40 | ytracks(points)=[];
|
---|
41 | points=find(track_values<0);
|
---|
42 | track_values(points)=[];
|
---|
43 | xtracks(points)=[];
|
---|
44 | ytracks(points)=[];
|
---|
45 |
|
---|
46 | points=find(xtracks<x_m(1) | xtracks>x_m(end) | ytracks<y_m(1) | ytracks>y_m(end));
|
---|
47 | track_values(points)=[];
|
---|
48 | xtracks(points)=[];
|
---|
49 | ytracks(points)=[];
|
---|
50 |
|
---|
51 | %initialize some matrices
|
---|
52 | numpoints=zeros(numrow,numcol);
|
---|
53 | value=zeros(numrow,numcol);
|
---|
54 | coordx=zeros(numrow,numcol);
|
---|
55 | coordy=zeros(numrow,numcol);
|
---|
56 |
|
---|
57 | %Loop over the points of the track
|
---|
58 | nel=size(track_values,1);
|
---|
59 | fprintf('%s',' track processing progress: 0.00 %');
|
---|
60 | for i=1:nel;
|
---|
61 | if mod(i,1000)==0,
|
---|
62 | fprintf('\b\b\b\b\b\b\b')
|
---|
63 | fprintf('%5.2f%s',i/nel*100,' %');
|
---|
64 | end
|
---|
65 |
|
---|
66 | x=xtracks(i);
|
---|
67 | y=ytracks(i);
|
---|
68 |
|
---|
69 | %get indices for the matrix
|
---|
70 | indexx=max(find(x_m<x));
|
---|
71 | indexy=max(find(y_m<y));
|
---|
72 |
|
---|
73 | %get weighing coefficient
|
---|
74 | val=track_values(i);
|
---|
75 |
|
---|
76 | %update numoverlap and weights
|
---|
77 | numpoints(indexy,indexx)=numpoints(indexy,indexx)+1;
|
---|
78 | value(indexy,indexx)=value(indexy,indexx)+val;
|
---|
79 | coordx(indexy,indexx)=coordx(indexy,indexx)+x;
|
---|
80 | coordy(indexy,indexx)=coordy(indexy,indexx)+y;
|
---|
81 |
|
---|
82 | end
|
---|
83 | if nel>1000,
|
---|
84 | fprintf('\b\b\b\b\b\b\b\b')
|
---|
85 | fprintf('%4.2f%s\n',100,' %');
|
---|
86 | end
|
---|
87 |
|
---|
88 | %Change the values of numoverlap to 1 if 0 since we are going to devide by this matrix
|
---|
89 | numpoints(find(~numpoints))=1;
|
---|
90 |
|
---|
91 | %Create the center of mass for coordiantes and values.
|
---|
92 | Mvalue=value./numpoints;
|
---|
93 | Mx=coordx./numpoints;
|
---|
94 | My=coordy./numpoints;
|
---|