I have $N$ matrices of the same dimensions $m$-by-$n$ which span some matrix-space. E.g. the canonical basis $E_{ij}$ where the $(i,j)$-th entry is one and all others are zero.
Now would like to store them in one quantity, say a $m$-by-$n$-by-$N$ matrix or a $N$-cell, in order to quickly get linear combinations of them by prescribing a coefficient vector and performing some sort of "matrix-vector-product", circumventing looping.
Is there an elegant way to do this?
PS: I would appreciate not to embed them as vectors in $R^{mn}$ because I want to use the result in a function that only accepts matrices, so the transformation would need to be inverted.
PPS: I actually use a more interesting basis than the above. The entries of the resulting linear combination are not immediately obvious from the coefficient vector.
A simple way is to use reshape. We start by creating a multidimensional array for some grid:
Now Z will be three 2x3 matrices, filled with 1s 2s and 3s. The size will be in this order:
[rows, columns, number of matrices]:
Say we want to sum all three of them we can just do:
The vector [1,1,1]' contain the coefficients of the linear combination.