How to export array elements?

2 次查看(过去 30 天)
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.

采纳的回答

Akira Agata
Akira Agata 2021-9-2
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)
{[ 1 2 11 12]} {[ 3 4 13 14]} {[ 5 6 15 16]} {[ 7 8 17 18]} {[9 10 19 20]}

更多回答(1 个)

Walter Roberson
Walter Roberson 2021-9-3
编辑:Walter Roberson 2021-9-3
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by