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 (최근 30일)

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)

채택된 답변

James Tursa
James Tursa 2015년 7월 2일
편집: James Tursa 2015년 7월 2일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by