How to shift the dimensions of a variable in a NetCDF file

3 visualizaciones (últimos 30 días)
Amalu A
Amalu A el 23 de Mzo. de 2019
Editada: Amalu A el 23 de Mzo. de 2019
I have a NetCDF(example file) file which have different variables inside it. Have to choose a particular variable from the file(Spectral_AOD_Scaling_Coeff) which has three dimensions say 4032 x 496 x 3. Iwant to rewrite the variable by shifting the third dimension to first and first in position of third, for my example 3 x 496 x 4032 to 4032 x 496 x 3 and save the variable to same file. I have a number of such NetCDF file to do this same work so looking for a code which takes each file from a folder, do the stuff. any help is appreciated.
Thanks in advance

Respuesta aceptada

Walter Roberson
Walter Roberson el 23 de Mzo. de 2019
I am not positive, but I think you might have to delete the variable out of the file before you can write in with the new ordering. But that is a bit of a problem, because netcdf does not have an explicit deletion interface.
It might be easier to copy all the variables to a new file, changing the one that is of interest to you.
The reorganization of the variable is easy at the MATLAB level:
permute(TheArray, [3 2 1])
But be careful, because netcdf are normally written in row-major order, whereas MATLAB works in column-major order. That is, in netcdf files, A(1,1) and A(1,2) are adjacent in the file, whereis in MATLAB, A(1,1) and A(2,1) are adjacent in memory. You should work out what order of elements you want to create in the file.
  1 comentario
Amalu A
Amalu A el 23 de Mzo. de 2019
Editada: Amalu A el 23 de Mzo. de 2019
Thanks for the answer, Yes you are right, I also found it is necessary to delete the existing variable but I cant do like that, so i tried to copy it to a new file and alter that. shiftdim(Array,1) gives the output I want but now the problem is wit writing it to the copied file. can you please go through my question.
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by