首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用for循环将一个包含60个4乘4矩阵的mat文件分解为60个不同名称的不同矩阵?

如何使用for循环将一个包含60个4乘4矩阵的mat文件分解为60个不同名称的不同矩阵?
EN

Stack Overflow用户
提问于 2016-08-16 05:09:06
回答 1查看 44关注 0票数 1

我有一个mat文件(AA),其中有60个矩阵。我希望将矩阵存储到单个矩阵中,并在for循环中使用不同的名称保存它们。但我得到了错误,我不知道如何摆脱。你有什么想法吗?

代码语言:javascript
复制
AA = randn(4,4,60);  % this is the matrix w/ 60 matrices in it
for i = 1:60
BB = zeros[4,4, length(AA)];  % pre-allocation
BB(:,:,i) = AA(:,:,i);
filename = ['BB-' num2str(i), 'mat'];  % rename the file to have different matrices
save(filename, 'BB')
end

但是它不能按照我想要的方式工作!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-16 05:18:18

下面是你如何做到这一点:

代码语言:javascript
复制
AA = randn(4,4,60);  % this is the matrix w/ 60 matrices in it
for i = 1:60
    BB = AA(:,:,i);
    filename = ['BB-' num2str(i), 'mat'];  % rename the file to have different matrices
    save(filename, 'BB')
end

不需要预先分配BB

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38963108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档