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

33 views (last 30 days)
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.
Abhishek Saini
Abhishek Saini on 4 Dec 2018
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;
elCnt = elCnt+1;
elNodes(1:8,elCnt) = cubeNodes(:);
elNodes = elNodes+1;

Sign in to comment.

Answers (2)

Caglar on 7 Nov 2018
Edited: Caglar on 7 Nov 2018

Stephen23 on 7 Nov 2018
Walter Roberson
Walter Roberson on 8 Nov 2018
.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.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!