I’m trying to write a short Matlab code to perform a certain mathematical function. The code generates a vector H which has entries of either 1, 2 or 3 (and size dependent on other factors). (In my mind), the numbers 1, 2 and 3 correspond to three particular matrices. Once my program has calculated H, I would like it to be able to multiply together all the matrices represented by its entries. To clarify, if H = [1 2 3 2], I’d like my code to calculate A*B*C*B. What is the simplest way of doing this? I thought about creating a vector with entries that are matrices, and using a function that gives the product of the entries of the vector, but I couldn’t get that to work (and don’t know if it can work – I’m very new to Matlab).
Ideally I’d rather not rewrite the rest of my code – if there’s a way to get this to work with what I’ve done so far then that’d be great. I’m looking for functionality as opposed to slick coding – it doesn’t matter if it’s clumsy, as long as it works.
@zuloos answer might be problematic if the sizes of matrices are not the same – especially if number of rows are different. Should work if you put the matrices in cells.