How to export array elements?
5 views (last 30 days)
Show older comments
Hi all,
I have an big array say the size is 40000 by 1 i.e. 40000 rows and 1 column. I want to export effeciently according to index as below
For make it simple.lets make the array A size 20 by 1
Now, export the array as X1 = [x1,x2,x11,x12];
X2 = [x3,x4,x13,x14];
X3 = [x5,x6,x15,x16];
X4 = [x7,x8,x17,x18];
X5 = [x9,x10,x19,x20];
Tannks in advance.
0 Comments
Accepted Answer
Akira Agata
on 2 Sep 2021
How about the following?
A = (1:20)';
N = numel(A);
idx = mod(0:N-1,10)' <= 1;
X = cell(5,1);
for kk = 1:5
X{kk} = A(idx)';
idx = circshift(idx,2);
end
disp(X)
More Answers (1)
Walter Roberson
on 3 Sep 2021
Edited: Walter Roberson
on 3 Sep 2021
per_group = 2; stride = 5;
B = reshape(permute(reshape(A, per_group, stride, []), [1 3 2]), per_group*stride, []);
The columns of B are now the extracts. You could num2cell(B,1) if you wanted to get them into individual cell arrays.
0 Comments
See Also
Categories
Find more on Matrices and Arrays 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!