extract value from a multidimentional array for exact value for two dimensions
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Galga
el 7 de Sept. de 2020
Respondida: Galga
el 16 de Sept. de 2020
Hi everyone,
I'm a beginner in matlab and I'm facing a probably simple problem that I'm not able to solve.
I have a set of netcdf files with climate data and I need to extract values of variables for specific lon lat location.
Each files has the following information:
ncdisp(filename)
Format:
classic
Global Attributes:
Conventions = 'CF-1.6'
production = 'CNRM-RCSM4 coupled model'
nco_openmp_thread_number = 1
NCO = '"4.5.5"'
institution = 'CNRM(Centre National de Recherches Meteorologiques),Meteo-France,Toulouse'
contact = 'florence.sevault@meteo.fr'
experiment_id = 'RCSM4-3.03'
frequency = 'mon'
creation_date = '2018-11-05 11:00:27'
Dimensions:
time = 120 (UNLIMITED)
y = 160
x = 394
Variables:
time
Size: 120x1
Dimensions: time
Datatype: double
Attributes:
units = 'months since 2006-01-01 00:00:00'
calendar = 'standard'
longitude
Size: 394x160
Dimensions: x,y
Datatype: single
Attributes:
standard_name = 'longitude'
units = 'degrees_east'
latitude
Size: 394x160
Dimensions: x,y
Datatype: single
Attributes:
standard_name = 'latitude'
units = 'degrees_north'
zos
Size: 394x160x120
Dimensions: x,y,time
Datatype: single
Attributes:
units = 'm'
_FillValue = 1.000000020040877e+20
cell_methods = 'time_counter: mean'
coordinates = 'longitude latitude'
standard_name = 'sea_surface_height_above_geoid'
valid_min = -1.000000020040877e+20
valid_max = 1.000000020040877e+20
missing_value = 1.000000020040877e+20
cell_method = 'time:mean'
offline_operation = 'zos=zos+0.11'
For the "zos" variable (394x160x120) I need to extract all 120 time value for given location (i.e. lon=12.48 lat= 44.64). I've tried different approaches, based on solved problems, but none of them work.
For example, with getvalue:
lat=ncread(filename,'latitude');
lon=ncread(filename,'longitude');
zos=ncread(filename,'zos');
data=getValue(12.48, 44.64, lon, lat, zos);
I have the following error:
Check for missing argument or incorrect argument data type in call to function 'getValue'.
Any suggestion?
Thanks in advance!
0 comentarios
Respuesta aceptada
Más respuestas (1)
Anmol Dhiman
el 11 de Sept. de 2020
Hi Galga,
I understand that you want to extract all 120 time value for given location (lattitude , longitude) from zos where zos is a 3D variable having size 394x160x120.
You can use the following code
lat = ; % the latittude value
lon = ; % the longitude value
values = zos(lat,lon,:); % the values is of dimentsion [1x1x120] and we need to reshape it.
newValue = reshape(values,[1,120]); % new values contain all the time value for a given location.
If you want to use it many times consider creating a function.
Regards,
Anmol Dhiman
5 comentarios
Anmol Dhiman
el 14 de Sept. de 2020
Editada: Anmol Dhiman
el 14 de Sept. de 2020
Hi Gaia,
I have checked the dataset given, The above error is coming as zos contains NaN values. Can you verify from your end.
Regards,
Anmol Dhiman
Ver también
Categorías
Más información sobre NetCDF en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!