How to create large data in MATLAB. For large array showing out of memory.

52 ビュー (過去 30 日間)
Abhishek Saini
Abhishek Saini 2018 年 11 月 7 日
コメント済み: Abhishek Saini 2018 年 12 月 4 日
I am trying to generate 3D mesh for my finite element simulation in MATLAB.But due to large number of nodes or array size it is giving error * "out of memory"*. The array size is more than 500 millions. I am using MATLAB in Linux system. How can I generate large data in MATLAB? Please guide me.
Thanks!
  2 件のコメント
Abhishek Saini
Abhishek Saini 2018 年 12 月 4 日
You could use repmat to generated repeated mesh. Here is the code you could use. i hope this will help you.
%dx, dy, dz - spacing in each direction
dx=0.5; dy=0.5; dz=0.5;
% number of nodes in x, y and z directions
nx= 500; ny = 500; nz=500;
% mesh centre in each direction
cx=0; cy = 0; cz=0;
%define nodes
px = repmat( dx*( (1:nx)-(nx+1)/2 ).', [1,ny,nz])+cx;
py = repmat(dy*( (1:ny).'-(ny+1)/2).', [nx,1,nz] )+cy;
pz = repmat(dz*permute( (1:nz).'-(nz+1)/2,[2,3,1]), [nx,ny,1] )+cz;
px = reshape(px,[],1); py = reshape(py,[],1); pz = reshape(pz,[],1);
nodePos = [px(:), py(:), pz(:)].';
nEls = (nx-1)*(ny-1)*(nz-1); % total number of elements
n = 8; % cubic element
elNodes = zeros(n,nEls);
cubeNodes = zeros(8,1);
elCnt = 0;
for elCntZ = 1:(nz-1)
for elCntY = 1:(ny-1)
for elCntX = 1:(nx-1)
cubeNodes(1) = elCntX-1 + (elCntY-1)*nx + (elCntZ-1)*nx*ny;
cubeNodes(2) = elCntX + (elCntY-1)*nx + (elCntZ-1)*nx*ny;
cubeNodes(3) = elCntX + (elCntY )*nx + (elCntZ-1)*nx*ny;
cubeNodes(4) = elCntX-1 + (elCntY )*nx + (elCntZ-1)*nx*ny;
cubeNodes(5) = elCntX-1 + (elCntY-1)*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(6) = elCntX + (elCntY-1)*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(7) = elCntX + (elCntY )*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(8) = elCntX-1 + (elCntY )*nx + (elCntZ-1+1)*nx*ny;
%hex:
elCnt = elCnt+1;
elNodes(1:8,elCnt) = cubeNodes(:);
end
end
end
elNodes = elNodes+1;

サインインしてコメントする。

回答 (2 件)

Caglar
Caglar 2018 年 11 月 7 日
編集済み: Caglar 2018 年 11 月 7 日

Stephen23
Stephen23 2018 年 11 月 7 日
  2 件のコメント
Walter Roberson
Walter Roberson 2018 年 11 月 8 日
.mat files are not usually datastores themselves. You can use a custom read function to use them as a datastore but you need to tell it what kind of data is being processed.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by