I want to export my variabels to a single .nc file

1 vue (au cours des 30 derniers jours)
ima
ima le 27 Fév 2023
Modifié(e) : Walter Roberson le 15 Août 2024
Hello.
I have a set of variables that i want to export as one .nc file so that i can use the dataset later on. I have tried using the instructions listed in this thread but it keeps returning an error. I'll include my code and the variables that i use below. And sorry for the rudamentary code, I'm still new to matlab
clear
clc
%masukin waktu
waktu= ncread('FABMSAT.nc','time');
waktu= waktu';
%masukin fito layer 1
fito= ncread('FABMSAT.nc','npzd_phy');
fito= fito(:,1,:);
%masukin pasut
pasut= ncread('FABMSAT.nc','zeta');
% masukin vector u
u= ncread('FABMSAT.nc','u');
u= u(:,1,:);
%Masukin vector v
v= ncread('FABMSAT.nc','u');
v= v(:,1,:);
%CUT SUPAYA MULAI 1 FEB 2022
waktu_feb= waktu;
waktu_feb(:,[1:168])=[];
fito_feb= fito;
fito_feb(:,[1:168])=[];
pasut_feb= pasut;
pasut_feb([2:8307],:)=[];
u_feb= u;
u_feb(:,[1:168])=[];
v_feb= v;
v_feb(:,[1:168])=[];
%define dimensions
netcdf.setDefaultFormat('NC_FORMAT_CLASSIC');
ncid = netcdf.create('test.nc','NC_WRITE');
dimidfito = netcdf.defDim(ncid,'fito_feb',fito_feb);
%Define the name of variable
var_fito = netcdf.defVar(ncid, 'fito_feb','NC_FLOAT',[dimidfito]);
%variables into .nc file
netcdf.endDef(ncid);
netcdf.putVar(ncid,var_fito,fito_feb);
netcdf.close(ncid);

Réponses (1)

Amith
Amith le 15 Août 2024
Hi Ima,
To export your variables into NetCDF files, you can utilize MATLAB's NetCDF capabilities. To write variables into ".nc" files, you can use :
>> ncwrite("myfile.nc", "variablename", value)
For more information on creating and merging NetCDF files, along with additional details, please refer to the resource linked below:
Hope this helps!

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by