regriding an irregular matrix
Mostrar comentarios más antiguos
Dear all,
I have a 3D irregular matrix in time and position below :
A = 3000 x 3
Column1 = time (vary from 2002-2005)
Column2 = Longitude (vary from 40-50)
Column3 = Value
A = [2Jan2002 40 65
6Jan2002 45 22
8Jan2002 43 45
8Jan2002 49 64
30Jan2002 42 78
4Feb2001 43 56
6Feb2001 47 67
: : :
23Nov2005 44 76
3Dec2005 42 89
5Dec2005 48 67
9Dec2005 44 78
13Dec2005 41 89
19Dec2005 49 34
23Dec2005 45 67
24Dec2005 43 88
31Dec2005 47 34];
I want to regridding this irregular data in time and position into regular matrix based on monthly (2002-2005; so 48 month) and 1 degree lon position (40-50; so 10 points), in summary the output mtrix will be 10x48.
Some points longitude will have NaN value cause no record in this months at x longitude.
Anyone can help?
Best regards,
1 comentario
This is not a valid array as it mixes strings and numeric values. How are your data truly stored at this point? If you have time, longitude, and value, you just need a 2D array, as you are mentioning later in the question when you define the dimension of your final array. Do you have in fact something like a 3 columns CSV or Excel file with the original data? If so, assuming that we can treat "31Dec2005"-like timestamps correctly, how do you want to summarize values on a per month basis; is it a simple average?
Respuesta aceptada
Más respuestas (3)
m0xty Wilopo
el 8 de Mayo de 2013
0 votos
A general approach could be the following, assuming that you have this matrix A with datenums in the first row.
[y, m] = datevec(A(:,1)) ;
dateId = ((y - min(y))*12 + m).' ;
nYears = range(y) + 1 ;
lonId = A(:,2) - min(A(:,2)) + 1 ;
nLon = range(A(:,2)) + 1 ; % You might want to fix this
% instead of having it flexible.
dataArray = nan(nLon, nYears*12) ;
ind = sub2ind(size(dataArray), lonId, dateId) ;
dataArray(ind) = A(:,3) ;
Now, as mentioned in my comment, we should improve it a bit if you can have cases where there are multiple values for the same pairs dateId/lonId. Just let me know and we can extend it using ACCUMARRAY.
m0xty Wilopo
el 9 de Mayo de 2013
1 comentario
Andrei Bobrov
el 10 de Mayo de 2013
Please see my answer after edited.
Categorías
Más información sobre Graph and Network Algorithms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!