I have 60*3 Matrix. i have store it into L. then i have to allocate these value as (L1, L2, L3, L4.......L20) for 20 matrix. how can i allocate. please tell me command or allocation

1 view (last 30 days)

L =

   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.7568e-12   -2.027e-12            0
   -2.027e-12   1.0363e-10            0
            0            0   2.1978e-10
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
   6.1028e-11  -4.8863e-11            0
  -4.8863e-11   6.1028e-11            0
            0            0   2.6185e-11
%formula for allocation 
allL(3*k-2:3*k,1:3)=L(1:3,1:3);
L(1:3,1:3)=allL(1:3,1:3)

Accepted Answer

James Tursa
James Tursa on 2 Jul 2015
Edited: James Tursa on 2 Jul 2015
If you are trying to create 20 different variables named L1, L2, ..., L20, this is a bad idea. It will be difficult to write good code downstream and will be much harder to maintain. Instead, consider organizing your data into slices that can be indexed. E.g., one method using cell arrays:
LC = mat2cell(L,3*ones(20,1),3);
Then downstream in your code you would use LC{1} instead of L1, and LC{2} instead of L2, etc. That way you can write indexed loops to use these matrices.
Another way would be to organize the data into a 3D array where the first 2D slices are your 3x3 matrices. E.g.,
LA = permute(reshape(L',3,3,20),[2 1 3]);
Then downstream in your code you would use LA(:,:,1) instead of L1, LA(:,:,2) instead of L2, etc. Again, this allows you to write indexed loops to use these matrices. This storage scheme also allows you to use some of the nD matrix algebra packages in the FEX.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!