创建矩阵列表 [英] Creating a list of matrices
问题描述
我是编程新手,我想知道我的问题是否有简单的实现.我有一堆矩阵,我想要一种方法来存储它们,或者能够轻松地调用它们并对它们进行操作.例如,如果我有100个矩阵,分别称为M1,M2,... M100;有没有一种方法可以重命名它们,以便如果我想调用第n个矩阵,我可以只写M(nth)?
I am new to programming and I was wondering if my question has a simple implementation. I have a bunch of matrices and I want a way to be able to store them, or be able to easily call them and do operations on them. For example, if I have 100 matrices, called, M1,M2,...M100; is there a way I can rename them so that if I want to call the nth matrix, I can just write M(nth)?
例如,如果我要添加M1 + M1,M1 + M2,...,M1 + M100;我希望能够编写类似这样的循环,
For example, if I want to add M1+M1, M1+M2, ...,M1+M100; I want to be able to write a loop something kind of like,
对于i = 1:100 AM(i)= M(1)+ M(i) 结束
for i=1:100 AM(i)=M(1)+M(i) end
这可能吗?
推荐答案
使用单元格数组
AM = cell(1,100);
并将其设置为
AM{i} = Mi;
然后您就可以访问它
AM{i};
请注意使用{}访问单元阵列AM的每个元素,即矩阵.
note the use of {} to access each element of the cell array AM, that is in turn a matrix
这篇关于创建矩阵列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!