
Re-sizing matrixes extracted from NetCFD files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
TIMOTHEE DE TOLDI
le 26 Juin 2021
Commenté : Scott MacKenzie
le 28 Juin 2021
Hi all,
I am facing a problem to which I can't seem to find a fitting answer in the already posted Q&A.
I have extracted data (temperature and population) from NetCFD files coming from several global models and global climate models (i.e. different resolutions) and find myself with several 2D matrixes (lat*lon).
Here is my problem:
I need to resize the matrixes coming from higher resolution models to fit the size of the ones with lower resolution.
Yet there's a twist:
- I need to go from a 320*180 population matrix (data_pop) to a 192*145 one (data_pop_new): I therefore need to reduce the size without loosing any data (the lower resolution matrix needs to display more or less the same total population).
- I need to go from a 320*160 temperature matrix (data_tas) to a 192*145 one (data_tas_new): I therefore need to reduce the size and to average the data instead of adding it (as temperature data don't add themselves).
The problem is therefore twofold : (i) how to resize a matrix to an odd size which isn't a perfect multiple of the original size, and (ii) how to do it either by averaging the data, or by adding the data.
A sample code of the manipulation to do would be truly helpful.
Thank you in advance.
0 commentaires
Réponse acceptée
Scott MacKenzie
le 26 Juin 2021
Modifié(e) : Scott MacKenzie
le 26 Juin 2021
I think you can leverage the image stretching function imresize to your application. The destination matrix can be any size and the new data are faithful to the original data:
M1 = peaks;
M2 = imresize(M1, [33 77])
tiledlayout(2,1)
nexttile;
surf(M1)
nexttile;
surf(M2);

6 commentaires
Scott MacKenzie
le 28 Juin 2021
@TIMOTHEE DE TOLDI You're welcome. And here's a quick demo using imresize of @Walter Roberson's instructions:
M1 = [1 2 3; 6 5 4; 1 5 9; 5 5 5]
sum1 = sum(sum(M1))
M2 = imresize(M1,1.5)
sum2 = sum(sum(M2))
M3 = M2 * sum1/sum2
sum3 = sum(sum(M3))
M1 =
1 2 3
6 5 4
1 5 9
5 5 5
sum1 =
51
M2 =
0.57369 1.151 1.9947 2.8066 3.0729
3.8342 3.6758 3.4443 3.2215 3.1484
5.6737 5.4366 5.0903 4.7569 4.6476
1.1778 3.0061 5.6775 8.2488 9.092
2.5269 3.6992 5.4122 7.0609 7.6016
5.2971 5.1562 4.9505 4.7524 4.6875
sum2 =
130.87
M3 =
0.22356 0.44854 0.77729 1.0937 1.1975
1.4941 1.4324 1.3422 1.2554 1.2269
2.2109 2.1186 1.9836 1.8537 1.8111
0.45897 1.1714 2.2125 3.2144 3.543
0.9847 1.4415 2.109 2.7515 2.9622
2.0642 2.0093 1.9291 1.852 1.8266
sum3 =
51
Plus de réponses (1)
Walter Roberson
le 28 Juin 2021
To resize a matrix while keeping the totals the same, resize the matrix first, calculate the total of the resized, and then multiply the resized matrix by old_total/new_total
Voir également
Catégories
En savoir plus sur Time Series Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

