在MATLAB中将多个二维.mat文件转换为单个三维.mat



我有79个.mat文件,每个文件都包含一个名为"CM"的264*264数组。我想把它们组合成一个单独的264*264*79矩阵,但我不知道怎么做。

files=dir('*.mat') %// load all filenames from the directory ending on .mat
for ii = numel(files):-1:1 %// let the loop run backwards
    load(files(ii).name);
    A(:,:,ii) = CM; %// assumed they are actually all equivalently called CM
end

dir命令获取pwd(当前工作目录)中所有文件的列表。for循环向后运行,以便将存储变量A初始化为其最大大小,从而提高效率。在循环中,加载一个文件,然后将其存储在A中。最后,A将是[264 264 79]阵列。

最新更新