Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a list of matrices [duplicate]

Tags:

matlab

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)?

EDIT: 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,

for i=1:100 AM(i)=M(1)+M(i) end

Is this possible?

like image 726
user2540462 Avatar asked Dec 15 '22 09:12

user2540462


1 Answers

Use cell array

AM = cell(1,100);

and set it as

AM{i} = Mi;

then you can access it as

AM{i};

note the use of {} to access each element of the cell array AM, that is in turn a matrix

like image 90
innoSPG Avatar answered Dec 28 '22 03:12

innoSPG