[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #AWJ-248197]: Writing data into a netCDF file through Matlab



Hi Bindu,

Sorry to have taken so long to respond to your question ...
> I am trying to wirte into a netCDF file through Matlab. But I keep getting
> the following error
> 
> status = mexnc('PUT_VAR_DOUBLE',ncid,varid,'regionmask')
> 
> ??? Error using ==> netcdflib
> The number of input elements does not match the variable size.
> 
> Error in ==> putVar at 75
> netcdflib(funcstr,ncid,varid,varargin{:});
> 
> Error in ==> mexnc_tmw>handle_put_var at 1320
> netcdf.putVar(varargin{2:end})
> 
> Error in ==> mexnc_tmw at 115
> [varargout{:}] = handler ( varargin{:} );
> 
> Error in ==> mexnc at 569
> [varargout{:}] = mexnc_tmw(varargin{:});
> 
> 
> The dimensions that I am trying to write are what I defined the variable
> for, nevertheless I did play around with dimensions. But no combination
> worked. I have tried everything I can think of. I can't figure out how to
> write into the file. I can add new variables into the netCDF file but cannot
> add data to it. I am new to netCDF, maybe I am missing something. I would
> really appreciate any help.

> status = mexnc('PUT_VAR_DOUBLE',ncid,varid,'regionmask')
> 
> ??? Error using ==> netcdflib
> The number of input elements does not match the variable size.

It may be that your dimensions are in the reverse order of what you
think they should be.  As it says in the MATLAB help for netCDF:

    NetCDF files use C-style row-major ordering for multidimensional
    arrays, while MATLAB uses FORTRAN-style column-major ordering.
    This means that the size of a MATLAB array must be flipped
    relative to the defined dimension sizes of the netCDF data set.
    For example, if the netCDF dataset has dimensions 3x4x5, then the
    equivalent MATLAB array has size 5x4x3.  The PERMUTE command is
    useful for making any necessary conversions when reading from or
    writing to netCDF data sets.

If that's not the problem, you may have to seek help from MATLAB
support, as we don't have a MATLAB expert here.

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: AWJ-248197
Department: Support netCDF
Priority: High
Status: Closed