How I can split a two column data into chunks like this snap shot
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Voss
2023-10-24
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);
0 个评论
更多回答(1 个)
Fabio Freschi
2023-10-24
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,[])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!