How I can split a two column data into chunks like this snap shot

5 views (last 30 days)
Hello,
I have attached a mat file and I want to chunk my data in equal number of arrays like the attached image. Since I am dealing with a large data set of around 200 files of data and I have to do this iteration for every file and plot it. so kindly guide me and help me in chunking and plotting automatically as currently i am doing it manually with every file and using excel tool for data chunking and plotting.
Looking forward to your comments.

Accepted Answer

Voss
Voss on 24 Oct 2023
S = load('Data_Chunking.mat');
A = S.Alg2_mLat_maxEE;
C = 9; % chunk size
[M,N] = size(A);
% in case A is not an integer number of chunks tall,
% append A with rows of NaNs to make it an integer
% number of chunks tall
m = mod(M,C);
if m
A = [A; NaN(C-m,N)];
M = M+C-m;
end
% now do the chunking:
A_chunked = reshape(permute(reshape(A(:,[2 1]),C,[],2),[1 3 2]),C,[]);
% make a table out of the chunked matrix (may be easier to see/deal with):
T = array2table(A_chunked,'VariableNames',["Number of Iterations";"Value"]+(1:M/C));
disp(T);
Number of Iterations1 Value1 Number of Iterations2 Value2 Number of Iterations3 Value3 Number of Iterations4 Value4 Number of Iterations5 Value5 Number of Iterations6 Value6 Number of Iterations7 Value7 Number of Iterations8 Value8 Number of Iterations9 Value9 Number of Iterations10 Value10 _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ _____________________ ______ ______________________ _______ 6 1.8523 60 150.95 114 653.51 168 1255.6 222 1742.1 276 3096.1 330 5273.5 384 7019.8 438 11964 492 38570 12 19.743 66 253.64 120 700.77 174 1295.8 228 1844.4 282 3262.5 336 5717.7 390 8261.9 444 12519 498 53695 18 29.175 72 461.59 126 715.14 180 1362.6 234 1865.4 288 3444.9 342 6003.9 396 8451.5 450 12572 NaN NaN 24 32.305 78 498.31 132 782.68 186 1476 240 1888.7 294 3827.6 348 6040.7 402 8513.5 456 14272 NaN NaN 30 43.65 84 501.85 138 843.13 192 1479.2 246 1919.9 300 3971.6 354 6346 408 9886.9 462 16234 NaN NaN 36 74.47 90 521.24 144 1007.4 198 1561 252 2036.2 306 4210.5 360 6380.8 414 10094 468 23964 NaN NaN 42 87.369 96 529.57 150 1130.1 204 1569.2 258 2477.3 312 4406.3 366 6536.9 420 10157 474 28829 NaN NaN 48 118.96 102 585.18 156 1193.9 210 1700.7 264 2741.2 318 4577.2 372 6549 426 10180 480 32492 NaN NaN 54 142.44 108 614.52 162 1216.2 216 1707.2 270 3020 324 4890 378 6997.9 432 10934 486 33161 NaN NaN

More Answers (1)

Fabio Freschi
Fabio Freschi on 24 Oct 2023
If I have understood correctly, this code should to the job. Note that 83 is a prime number, so it is difficult to create chunks. I have kept the first 80 rows
load('Data_Chunking.mat');
% remove three rows to make it "chunkable"
A = Alg2_mLat_maxEE(1:80,:);
% number of rows per chunk
N = 5;
% reshape to have N rows
B = reshape(permute(reshape(A,N,[],2),[1 3 2]),N,[])
B = 5×32
1.0e+04 * 0.0002 0.0006 0.0074 0.0036 0.0254 0.0066 0.0530 0.0096 0.0715 0.0126 0.1194 0.0156 0.1476 0.0186 0.1707 0.0216 0.1920 0.0246 0.3096 0.0276 0.4210 0.0306 0.5718 0.0336 0.6537 0.0366 0.8451 0.0396 1.0180 0.0426 0.0020 0.0012 0.0087 0.0042 0.0462 0.0072 0.0585 0.0102 0.0783 0.0132 0.1216 0.0162 0.1479 0.0192 0.1742 0.0222 0.2036 0.0252 0.3263 0.0282 0.4406 0.0312 0.6004 0.0342 0.6549 0.0372 0.8513 0.0402 1.0934 0.0432 0.0029 0.0018 0.0119 0.0048 0.0498 0.0078 0.0615 0.0108 0.0843 0.0138 0.1256 0.0168 0.1561 0.0198 0.1844 0.0228 0.2477 0.0258 0.3445 0.0288 0.4577 0.0318 0.6041 0.0348 0.6998 0.0378 0.9887 0.0408 1.1964 0.0438 0.0032 0.0024 0.0142 0.0054 0.0502 0.0084 0.0654 0.0114 0.1007 0.0144 0.1296 0.0174 0.1569 0.0204 0.1865 0.0234 0.2741 0.0264 0.3828 0.0294 0.4890 0.0324 0.6346 0.0354 0.7020 0.0384 1.0094 0.0414 1.2519 0.0444 0.0044 0.0030 0.0151 0.0060 0.0521 0.0090 0.0701 0.0120 0.1130 0.0150 0.1363 0.0180 0.1701 0.0210 0.1889 0.0240 0.3020 0.0270 0.3972 0.0300 0.5273 0.0330 0.6381 0.0360 0.8262 0.0390 1.0157 0.0420 1.2572 0.0450

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!