How I can split a two column data into chunks like this snap shot
2 ビュー (過去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1520296/image.png)
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!