美文网首页
matlab读写nc、csv、txt数据(待补充)

matlab读写nc、csv、txt数据(待补充)

作者: Aerosols | 来源:发表于2019-05-24 11:38 被阅读0次

(1)matlab读取不规则txt,http://weather.uwyo.edu/upperair/seasia.html

image.png
数据介绍
http://bbs.06climate.com/forum.php?mod=viewthread&tid=30664&page=1

后面也有很多行站点描述,不需要读取

参考
https://blog.csdn.net/Alpine_Climbing/article/details/52522808

 fid=fopen(filename,'r');
 FormatString=repmat('%f ',1,11);%%列数
out=cell2mat(textscan(fid,FormatString,18,'HeaderLines',6)); % FormatString后是读的行数, %%%Headlines是跳6行

(2)matlab读取csv

filename = strcat('E:\hour_ds.csv');
L1 = xlsread(filename,'hour_ds','D2:GB1417');

(3)matlab读取nc (试了txt,发现还是nc好用)

path = 'E:\wd.nc';  
wd = ncread(path,'WD')';

(4)matlab写nc

 dayn=23;
 varn=9;
 ctn=5;
 casn=4;
 
 %%%% 1.写nc文件
 cid = netcdf.create('ct.nc','SHARE');
 
 %%%% 2.定义Dimension
 dimday=netcdf.defDim(cid,'dayn',dayn);
 dimvar=netcdf.defDim(cid,'varn',varn);
 dimct=netcdf.defDim(cid,'ctn',ctn);
 dimcas=netcdf.defDim(cid,'casn',casn);
 
 %%%% 3.定义变量
 ctrid=netcdf.defVar(cid,'ctr','double',[dimday dimvar dimct]);
 casid=netcdf.defVar(cid,'cas','double',[dimcas dimvar dimct]);
 
 %%%%4.完成netcdf文件定义模式
 netcdf.endDef(cid);
 
 %%%5.把数据写到cetcdf文件中
 netcdf.putVar(cid,ctrid,newresult);
 netcdf.putVar(cid,casid,casave);
 
 
 %%% 6.关闭文件
 netcdf.close(cid);

相关文章

网友评论

      本文标题:matlab读写nc、csv、txt数据(待补充)

      本文链接:https://www.haomeiwen.com/subject/scowzqtx.html