我正在運行一個m文件,創建兩個變量Clus
和Watts_Map
。我想將這兩個變量保存到以「.mat」結尾的文件中。這兩個變量的尺寸爲(1152,241,319),其中1152爲360度的經度,增量爲0.3125度,241的緯度爲30S-30N,增量爲0.25度,時間跨度爲319。代碼工作一路才結束,在那裏我得到的錯誤:保存.mat文件,使用-v7.3開關?
[Warning: Variable 'Clus' cannot be saved to a MAT-file whose version is older
than 7.3.
To save this variable, use the -v7.3 switch.
Skipping...]
[Warning: Variable 'Watts_Map' cannot be saved to a MAT-file whose version is
older than 7.3.
To save this variable, use the -v7.3 switch.
Skipping...]
我用Matlab版本R2014a,所以會認爲這是最新版本。此外,我已經在較小的空間域上運行了相同的確切代碼(但超過2920個時間步長)而沒有錯誤。
% Clear all variables, initialize counter, indexed by timestep
clc;
clear all;
rain = NaN(1152,241,319);
Clus = NaN(1152,241,319);
Areas_Final = NaN(500,319);
Wattage_Final = NaN(500,319);
Cluster_size = zeros(319,1);
Watts_Map = zeros(1152,241,319);
for year = 2000%:2008;
Nyear = sprintf('%04d',year);
% Call on the files for each year
filename = (['pr_3hr_GFDL-HIRAM-C360_amip_r1i1p1_' num2str(Nyear) '010100-' num2str(Nyear) '123123_subset_TROPICS.nc']);
disp(filename)
disp(year)
rain_rate = ncread(filename,'pr');
% Call on each timestep
for i = 960:4:2236; % Approx May 1st-Sep 30th
% Set extract subset for region, mask land areas, for each
% timestep
disp(i)
rain = rain_rate(:,:,i);
% Eliminate bad/no data points
index_rain = (rain >= (5.4e-05)) & (rain < 1e-2); % 0.2mm/hr is min rain rate
% Cluster each morning and afternoon matrix
Clus(:,:,i) = cluster_it(index_rain);
% Calculate cluster areas
Areas = cluster_areas_TROPICS(Clus(:,:,i));
Areas_Final(1:length(Areas),i) = Areas;
% Calculate cluster wattages
Wattage = cluster_wattage(Clus(:,:,i),rain);
Cluster_size(i,1) = max(max(Clus(:,:,i)));
% Create dummy matricies to populate and use to create the wattage
% maps
D = zeros(1152,241);
E = squeeze(Clus(:,:,i));
for index = 1:Cluster_size(i);
D(E == index) = Wattage(index);
end
Watts_Map(:,:,i) = D;
% Clear the dummy matricies
clear D E
end
% Save the output as a .mat file
file_out = sprintf(num2str(Nyear), year);
matfile = [file_out '_TROPICS_Watts_Maps_inc_Land_low_rain_threshold.mat'];
save(matfile, 'Clus', 'Watts_Map');
% Clear unneeded variables to save memory and prevent overwriting
clear index_rain rain Areas Wattage Clus file_out filename Areas_Final rain_rate Watts_Map Cluster_size year matfile
end
v7.3只是一個略微修改的HDF5格式 - HDF5可以使用壓縮,而快速測試表明MATLAB確實可以壓縮數據。對我來說,保存在v6,v7和v7.3中的數據分別生成大小分別爲14MB,989KB和943KB的文件。這表明v7.3不僅可以壓縮數據,而且有時可以擊敗v7壓縮。至於爲什麼MATLAB在默認情況下不使用v7.3,可能是因爲文件大小對於複雜的嵌套結構/單元陣列有點過分。 – MrAzzaman 2014-12-02 01:32:23
@MrAzzaman很高興知道它壓縮。它不習慣,而且這個事實是一個很大的缺陷。根據[發行說明],它看起來像是R2008a(http://www.mathworks.com/help/matlab/release-notes-older.html#br0xe_f)。 – chappjc 2014-12-02 01:34:06