Taking the Inverse of a Tall Array To Solve a Linear System of Equations

1 次查看(过去 30 天)
Hi, I'm working with some large data sets and have begun using tall arrays for the first time. I was happy to hear that the inverse function (\) was available for tall arrays, but am having some trouble on implementation. Below is a none-working example (you may need to set your own output directory), if F is tall or not doesn't change anything.
function [SOL] = MinWorkExample
outDIR = 'M:\project\MATLAB Folder\PhD\TESTAREA\InterpolationForPaper\PHFtall';
fileIDX = 1;
rowsPerFile = 1e3;
rowsWritten = 0;
totalRows = 1e5;
while rowsWritten<totalRows
rowsToWrite = min(rowsPerFile, totalRows-rowsWritten);
datas = rand(1,totalRows);
fname = fullfile(outDIR,sprintf('datas_%05d.mat',fileIDX));
save(fname,'datas');
fileIDX = 1 + fileIDX;
rowsWritten = rowsToWrite + rowsWritten;
end
ds = fileDatastore(fullfile(outDIR, '*.mat'), ...
'ReadFcn', @(fname) getfield(load(fname), 'datas'), ...
'UniformRead', true);
CONMAT = tall(ds);
% Either F does not work.
% F = rand(totalRows,1);
F = tall(rand(totalRows,1));
SOL = CONMAT\F;

回答(1 个)

Ayden Clay
Ayden Clay 2020-5-23
So! I'm a collossal idiot. The error note was incredibly well written, and described my exact problem. Turns out that if I repeat the process but write in columns rather than rows, we're all good.
In the same nomenclature as the question, here is a working version:
function [SOL] = MinWorkExample
outDIR = '\PHFtall';
fileIDX = 1;
ColsPerFile = 1e3;
ColsWritten = 0;
totalCols = 1e5;
while ColsWritten<totalCols
colsToWrite = min(ColsPerFile, totalCols-ColsWritten);
datas = rand(totalCols,1);
fname = fullfile(outDIR,sprintf('datas_%05d.mat',fileIDX));
save(fname,'datas');
fileIDX = 1 + fileIDX;
ColsWritten = colsToWrite + ColsWritten;
end
ds = fileDatastore(fullfile(outDIR, '*.mat'), ...
'ReadFcn', @(fname) getfield(load(fname), 'datas'), ...
'UniformRead', true);
CONMAT = tall(ds);
F = tall(rand(1,totalCols));
SOL = CONMAT\F;
  1 个评论
Ayden Clay
Ayden Clay 2020-5-23
编辑:Ayden Clay 2020-5-23
Nevermind. This causes a further issue in that the data is vertically concatenated, producing a large Nx1 vector. Still working on a fix.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tall Arrays 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by