How to write a large matrix to a nc-file
조회 수: 8 (최근 30일)
이전 댓글 표시
I am trying to write a large matrix to a file using nccreate() and ncwrite(), but MATLAB is unfortunately crushing. Can you please provide a code example of how to write a matrix of, say 40K x 40x, in double precision?
댓글 수: 0
답변 (2개)
Jemima Pulipati
2020년 3월 13일
Here is a sample code which writes a 400 x 800 matrix to an NC file and retrieves the matrix from the file
and checks whether the data written matches or not using netcdf
numrow = 400;
numcol = 800;
my_data = rand(numrow,numcol);
ncid = netcdf.create('somefile.nc','NC_WRITE');
dimidrow = netcdf.defDim(ncid,'rows',numrow);
dimidcol = netcdf.defDim(ncid,'length',numcol);
varid = netcdf.defVar(ncid,'monthlypdsi','NC_DOUBLE',[dimidrow dimidcol]);
netcdf.endDef(ncid);
netcdf.putVar(ncid,varid,my_data);
netcdf.close(ncid);
ncid2 = netcdf.open('somefile.nc','NC_NOWRITE');
data_copy = netcdf.getVar(ncid2,0);
if isequal(my_data,data_copy)
disp('Data match');
else
disp('Data mis-match');
end
Hope it helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!