我有一些相同维度的气候数据文件(netcdf)。Matlab遍历文件夹中的文件,并检查文件名是否具有特定字符
例如: agg_humidity_bc_historical_1980_2001.nc
agg_humidity_bc_future_2020_2040.nc
agg_wind_bc_historical_1980_2001.nc
agg_precipitation_bc_future_2020_2040.nc
.....
我有一个计划MATLAB从中提取特定的数据点每一个文件。我想迭代所有文件,检查文件名中的变量名,例如湿度,风,降水等,并根据变量提取数据。然后我想存储这些提取的值与NC文件同名到CSV文件,如:
agg_humidity_bc_future_2020_2040.csv
agg_wind_bc_historical_1980_2001.csv
agg_precipitation_bc_future_2020_2040.csv
这里是我现在有的代码。
mkdir test
data=dir('*.nc');
for i=1:length(data)
ncFile=data(i).name
??? How to check which variable is in the ncFile?
%%Got the index of the location of
LonInd=22;
LatInd=10;
if variable=humidity
SH=ncread(ncFile,'humidity',[LonInd, LatInd, 1], [1 1 inf]);
SH=squeeze(SH);
fid = fopen(['test\' ncFile.csv],'w');
fprintf(fid,%d,SH)
else if variable=wind
wind=ncread(ncFile,'wind',[LonInd, LatInd, 1], [1 1 inf]);
wind=squeeze(wind);
fid = fopen(['test\' ncFile.csv],'w');
fprintf(fid,%d,wind)
fid = fclose(fid);
fid = fclose(fid);
else if variable=wind
precipitation=ncread(ncFile,'precipitation',[LonInd, LatInd, 1], [1 1 inf]);
precipitation=squeeze(precipitation);
fid = fopen(['test\' ncFile.csv],'w');
fprintf(fid,%d,precipitation)
fid = fclose(fid);
end
任何人都可以帮我完成这段代码吗?
感谢
http://www.mathworks.com/help/matlab/ref/regexp.html – user3528438