Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help! naming matrices in matlab

  1. Sep 18, 2010 #1
    I have created a program in MatLab doing LU factorization and need to implement a routine, so that MatLab automatically runs the program on all of my matrices.

    I have 6 matrices A1, A2, A3, A4, A5 and A6. But for the time being I can only run the program for one matrix, write the result down and then change the input matrix.

    Is there a smart way of making a loop so that MatLab automatically changes the input matrix?

    The notation A(i) does not work, since it refers to the elements in the matrix.
  2. jcsd
  3. Sep 18, 2010 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    look at sprintf() to write the variables then allocate A1 = zeros(x,x);

    Matlab is faster if you do not use loops, but write out the code as a list

    A1 = .....
    A2 = .....

  4. Sep 18, 2010 #3


    User Avatar
    Science Advisor
    Gold Member

    You can define a three-dimensional array A(l,m,n) so that one of your indices (I forget which one it is) points to the different matrices in a loop.
  5. Sep 20, 2010 #4


    User Avatar
    Gold Member

    you might want to check out 'struct' (in conjunction with 'sprintf').
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook