How to quote variables whose names are in order in a for loop?

1 view (last 30 days)
Hi! I want to store a 6D tensor A which is so large that I meet the 'out of memory' error. So I want to store it by parts. i.e. store A by sub-tensors A1,A2,...An. I know I can create variables whose name are in order by eval(). For example, I can create x1,...,x10 by:
VarNum = 10;
vars = [];
for i = 1:VarNum
eval([['x',num2str(i-1)],'=','i',';']);
end
But I don't know how to quote x1,...x10 in a for-loop when I don't store x1,...x10 into an array or cell which contains too large space and I will encounter 'out of memory' error. Can anyone help me? Thank you!
  7 Comments
Steven Lord
Steven Lord on 27 Apr 2021
An analogy that might make this clear is that of a hardcover version of the combined Lord of the Rings series of books. That volume requires a certain width of shelf space to store, and all that space has to be on the same shelf.
If you were to split the series into three volumes they would take up (basically) the same total width, but you could put the first volume on one shelf and the other two on the next shelf down. Though if you misplace volume 2 it could take you a while to find it when you want to read from it.
The combined hardcover is a double array, the three volumes are a cell array each cell of which contains part of the larger double array.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 7 Apr 2021
See if some of the tools in MATLAB for working with data that is too large to fit in memory on one machine all at once will satisfy your needs.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!