我有一个创建一堆 .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');
,这是来自第二列的字符串。