Extract data by skipping few numbers

2 views (last 30 days)
HYEJIN OH
HYEJIN OH on 12 Jul 2020
Answered: Walter Roberson on 12 Jul 2020
I tried to read binary data file in 1D and reshape this into 3D array, and it worked.
But since the data is very large, I want to skip few numbers. Full data size is 1024*1024*1024, so if I skip 2, then the array will be 512*512*512.
For now I am doing that by the code below. My question is, is there any way to reduce redundant arrays?
nx = 1024;
iskip = 4;
file1 = fopen(fullfile('E:\AUTOIGNITION\Z1\Velocity1_inertHIT.bin'),'r');
A = fread(file1,nx*nx*nx,'float32');
%A = fread(file1,nx/skip*nx/skip*nx/skip,'float32',skip);
fclose(file1);
U1 = reshape(A,nx,nx,nx);
U = zeros(nx/iskip,nx/iskip,nx/iskip);
for i = 1:nx/iskip
for j = 1:nx/iskip
for k = 1:nx/iskip
U(i,j,k) = U1(1+iskip*(i-1),1+iskip*(j-1),1+iskip*(k-1));
end
end
end

Answers (1)

Walter Roberson
Walter Roberson on 12 Jul 2020
After you do the reshape forming U1, then just do
U = U1(1:iskip:end, 1:iskip:end, 1:iskip:end);

Categories

Find more on Structures 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!