data structure for a matrix (2 dimensional) whose elements are a vector
1 view (last 30 days)
Show older comments
I'd like to encode a m-by-n matrix using matlab.
Problem is each element of the matrix should be a vector of size k.
How to encode this kind of matrix efficiently?
Thanks
Dohoon
0 Comments
Accepted Answer
James Tursa
on 7 Jun 2014
Edited: James Tursa
on 7 Jun 2014
For memory efficiency, you can use a 3D k-by-m-by-n array A. E.g.,
A(1:k,1,1) = 1st k-vector
A(1:k,2,1) = 2nd k-vector
etc
A(1:k,m,n) = last k-vector
Then each vector's elements would be contiguous in memory and could be extracted with the syntax A(:,x,y) for the "x-y-th" vector.
If you want the syntax to be more natural but give up a little in storage efficiency you can use a cell array. E.g.,
A(1,1) = {1st k-vector}
A(2,1) = {2nd k-vector}
etc
A(m,n) = {last k-vector}
The storage requirements are a bit more than the 3D array, but each vector's elements would still be contiguous in memory and could be extracted with the syntax A{x,y} for the "x-y-th" vector.
More Answers (0)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming 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!