MATLAB Answers

create matrix from string name

11 views (last 30 days)
Nihal Seegobin
Nihal Seegobin on 15 Apr 2019
Answered: madhan ravi on 15 Apr 2019
I want to create multiple matrices but i do not want to name each one but instead make matlab initialise one with every loop iteration.
I created var = "a",i = i+1,and then var = "a" + i, which would give me "a1", and then "a2", and so on. i want to make n x n matrices called a1, and another called a2, and so on.Each matrix is a (2:end,2:end) version of the previous one.

  1 Comment

KSSV on 15 Apr 2019
YOu need not name each about 3D matrices.
a = rand(2,2,2) ;
a(:,:,1) % a1
a(:,:,2) % a2

Sign in to comment.

Answers (1)

madhan ravi
madhan ravi on 15 Apr 2019
for k=1:4
a{k} = rand(2);


Sign in to comment.

Sign in to answer this question.




Translated by