我有一个创建大量.mat文件的代码,但我希望将它们保存为netcdf文件(csv或txt也可以),这样不能使用MATLAB的人就可以访问它们。到目前为止,这就是我所拥有的
%% Use function to read in
data = read_mixed_csv(filename,'"'); % Creates cell array of data
data = regexprep(data, '^"|"$',''); % Gets rid of double quotes at the start and end of the string
data = data(:,2:2:41); % Keep only the even cells because the odd ones are just commas
%% Sort data based on date (Column 1)
[Y,I] = sort(data(:,1)); % Create 1st column sorted
site_sorted = data(I,:); % Sort the entire array
%% Find unique value in the site data (Column 2)
% Format of site code is state-county-site
u_id = unique(site_sorted(:,2)); % get unique id
for i = 1:length(u_id)
idx=ismember(site_sorted(:,2),u_id{i}); % extract index where the second column matches the current id value
site_data = site_sorted(idx,:);
save([u_id{i} '.mat'],'site_data');
cdfwrite([u_id{i} '.nc'], 'site_data');
end一切都可以工作到第二行到最后一行。我想将每个'site_data‘写成一个netcdf文件,其名称与save([u_id{i} '.mat'],'site_data');相同,后者是第二列中的一个字符串。
发布于 2013-10-05 15:28:33
试一试
cdfwrite([u_id{i}],{'site_data',site_data})分机是‘..cdf’。我不确定在使用cdfwrite时是否可以更改这一点。
编辑:更正台风
https://stackoverflow.com/questions/19198882
复制相似问题