matlab读取nc\hdf\grd等气象文件 自用
作者:互联网
实现对气象数据文件的单个读取/查看数据
clc
clear
% %% 单个读取数据
path = 'D:\';
file_name = dir(fullfile(path,'*.grd')); % 存放文件的路径
for i =1%:length(file_name)
i
% %% 读取数据内容
file_path = strcat(path,file_name(i).name);
lon = ncread(file_path, 'lon');
lat = ncread(file_path, 'lat');
depth = ncread(file_path, 'z');
% %% 数据输出文本
new_file = '区域反演深度.txt';
fid = fopen(new_file,'w');
for m = 1:size(lon,1)
for n = 1:size(lat,1)
fprintf(fid, '%10.5f %10.5f %10.8f',lon(m,1),lat(n,1),depth(m,n));
fprintf(fid, '\n');
end
end
fclose(fid);
end
标签:fid,nc,lon,hdf,grd,file,lat,path,name 来源: https://blog.csdn.net/weixin_42983438/article/details/123127146