Usman Saleem asked . 2022-01-12

How to process NC file in matlab

I've monthly soil monisture NC file. This file contains monthly soil monisture data since 1948. I want to extract soil data within my shapefile in text file (Shapefile has also attached). I google alot to proccess NetCDF file in matlab find not solution, The ncdisp of my nc file is given below:

 

 

Format:
           netcdf4_classic
Global Attributes:
           _NCProperties = 'version=1|netcdflibversion=4.4.1.1|hdf5libversion=1.10.1'
           Conventions   = 'CF-1.0'
           title         = 'CPC Soil Moisture'
           institution   = 'NOAA/ESRL PSD'
           dataset_title = 'CPC Soil Moisture'
           history       = 'Wed Oct 18 15:13:37 2017: ncks -d time,,-2 soilw.mon.mean.x.nc soilw.mon.mean.xx.nc
                           Wed Oct 18 15:12:08 2017: ncks -d time,,-3 soilw.mon.mean.nc soilw.mon.mean.x.nc
                           CPC Soil Moisture
                            Obtained on Nov 2004 from CPC's website
                            and written to netCDF by Cathy Smith 12/2004.
                            he CPC Global monthly soil moisture dataset is a 1/2 degree resolution grid from 1948 to the present.
                            The file is written in COARDS and CF compliant netCDF at NOAA ESRL/PSD https://www.esrl.noaa.gov/psd/ 
                            Converted to chunked, deflated non-packed NetCDF4 Jul 2014'
           NCO           = '4.6.9'
           References    = 'https://www.psl.noaa.gov/data/gridded/data.cpcsoil.html'
Dimensions:
           lat  = 360
           lon  = 720
           time = 886   (UNLIMITED)
Variables:
    lat  
           Size:       360x1
           Dimensions: lat
           Datatype:   single
           Attributes:
                       long_name          = 'Latitude'
                       units              = 'degrees_north'
                       actual_range       = [8.98e+01 -8.98e+01]
                       standard_name      = 'latitude'
                       axis               = 'Y'
                       coordinate_defines = 'point'
    lon  
           Size:       720x1
           Dimensions: lon
           Datatype:   single
           Attributes:
                       long_name          = 'Longitude'
                       units              = 'degrees_east'
                       actual_range       = [2.50e-01 3.60e+02]
                       standard_name      = 'longitude'
                       axis               = 'X'
                       coordinate_defines = 'point'
    soilw
           Size:       720x360x886
           Dimensions: lon,lat,time
           Datatype:   single
           Attributes:
                       long_name     = 'Model-Calculated Monthly Mean Soil Moisture'
                       missing_value = -9.97e+36
                       units         = 'mm'
                       valid_range   = [0.00e+00 1.00e+03]
                       dataset       = 'CPC Monthly Soil Moisture'
                       var_desc      = 'Soil Moisture'
                       level_desc    = 'Surface'
                       statistic     = 'Monthly Mean'
                       parent_stat   = 'Other'
                       standard_name = 'lwe_thickness_of_soil_moisture_content'
                       cell_methods  = 'time: mean (monthly from values)'
                       actual_range  = [0.00e+00 1.00e+30]
    time 
           Size:       886x1
           Dimensions: time
           Datatype:   double
           Attributes:
                       long_name          = 'Time'
                       units              = 'days since 1800-01-01 00:00:0.0'
                       delta_t            = '0000-01-00 00:00:00'
                       avg_period         = '0000-01-00 00:00:00'
                       standard_name      = 'time'
                       axis               = 'T'
                       bounds             = 'time_bnds'
                       coordinate_defines = 'start'
                       prev_avg_period    = '0000-00-01 00:00:00'
                       actual_range       = [5.41e+04 8.10e+04]
                       
 

 

I've tied

  
  file='data.nc';
ncdisp(file)
long = ncread(file,'lon');
latt = ncread(file,'lat');
time = ncread(file,'time');

I want output of Soilw in this format in text file

Date        Soilw
01/01/2015   10
01/02/2015    20
01/03/2015    0.5

Please help me to convert monthly netcdf datainto text file using matlab please?

matlab gui , image processing , image analysis , netcdf

Expert Answer

Kshitij Singh answered . 2024-12-21 00:27:03

file = 'data.nc';
shapefile = 'lahore.shp';
long = ncread(file, 'lon');
latt = ncread(file, 'lat');
time = ncread(file, 'time');
soilw = ncread(file, 'soilw');
S = shaperead(shapefile);

%ncread sometimes returns the transpose of what we expect
if size(soilw, 1) ~= length(lat)
  soilw = permute(soilw, [2 1 3]);
end

Ntime = length(time);
Date = datetime('1800-01-01 00:00:00') + days(time(:));

mask = inpolygon(lat, lon, S.Y, S.X);  %caution, lat is Y not X !
Soilw = zeros(Ntime, 1);

for K = 1 : Ntime
  sl = soilw(:,:,K);
  Soilw(K) = mean( sl(mask) );
end

output = table(Date, Soilw);

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.