How to export array elements?

2 visualizaciones (últimos 30 días)
Rubel Ahmed
Rubel Ahmed el 2 de Sept. de 2021
Comentada: Rubel Ahmed el 3 de Sept. de 2021
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.

Respuesta aceptada

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

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de Sept. de 2021
Editada: Walter Roberson el 3 de Sept. de 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.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by