Form a huge matrix by mapping pre-existing vectors to matrix for memory saving?

1 view (last 30 days)
I need to form a huge matrix (say million by million), but the matrix has relatively simple structure, like (not my case, just for example)
1 2 3 4 5 10 20 30 40 50 1 2 3 4 5 10 20 30 40 50 ...
10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 ...
Basically this matrix is composed by some pre-existing vectors with certain patterns. I do not want to physically store this matrix, so I am wondering if there is any technique that can map those vectors to the matrix? In other words, I want a matrix holding no real data but pointers to other variables. When matlab works with the matrix, it actually goes to the vectors. Possible?
Thank you.
===========================================
More specific info regarding this question:
Here is an example: There are three row vectors in workspace
v1 = [1 2 3 4 5];
v2 = [10 20 30 40 50];
v3 = [10 9 8 7 6 5 4 3 2 1];
I want a matrix A, which is composed by v1, v2 and v3. A is a 10^6 by 10^6 matrix, whose
odd row: repeat [v1 v2] for 10^5 times
even row: repeat v3 for 10^5 times
A matrix will be multiplied by another column vector. I do not want to store A in my memory so I am looking for a method that maps those vectors v1, v2 and v3 to the (virtual?) matrix.

Answers (4)

Sean de Wolski
Sean de Wolski on 2 Mar 2011
Yes. It's possible.
  2 Comments
Sean de Wolski
Sean de Wolski on 2 Mar 2011
How are we possible supposed to know? The infinite monkey might stand a chance but you haven't given us any example of what you need. So you have a 2xn matrix, what does it do, what does it point to, what functions are you using it for etc.

Sign in to comment.


Matt Fig
Matt Fig on 2 Mar 2011
For a better answer, show a small example, complete with a small matrix and what you are going to do with it.

Jan
Jan on 2 Mar 2011
I'm very happy, that you do not want to store a "10^6 by 10^6" DOUBLE (?) matrix in the memory. Especially if it has such a low density of information.
But trying to map the vactors in a "virtual matrix" is either too vaguely explained or nonsense. What is a "virtual matrix"?!
Obviously there is no need to store the rows repeatedly. Create a 10^6 x 2 matrix and solve the rest by intelligent indexing:
v1 = [1 2 3 4 5];
v2 = [10 20 30 40 50];
v3 = [10 9 8 7 6 5 4 3 2 1];
M = [repmat([v1 v2], 1, 1E5); repmat(v3, 1, 1E5)];

Walter Roberson
Walter Roberson on 3 Mar 2011
define
Vsmall = [v1 v2;v3]
Then
V = @(R,C) Vsmall(1-mod(R-1,size(Vsmall,1)), 1 + mod(C-1,size(Vsmall,2)));
V is now your virtual array as far as indexing goes (i.e., suitable for your own matrix multiply algorithm)
When you are multiplying by a column vector, each row of A that is a repeat of an earlier row will have exactly the same result as the previous row.
The column-vector multiplication could potentially be sped up by knowing the structure of the columns of A. Or you could do something like
[B,m,n] = unique(A(P,:),'first');
sum(B .* accumarray(n, ColumnVector))
this would give you the result for the row P (and thus all rows that are duplicates of row P).

Categories

Find more on Creating and Concatenating Matrices 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!