How to export array elements?

2 vues (au cours des 30 derniers jours)
Rubel Ahmed
Rubel Ahmed le 2 Sep 2021
Commenté : Rubel Ahmed le 3 Sep 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.

Réponse acceptée

Akira Agata
Akira Agata le 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)
{[ 1 2 11 12]} {[ 3 4 13 14]} {[ 5 6 15 16]} {[ 7 8 17 18]} {[9 10 19 20]}
  1 commentaire
Rubel Ahmed
Rubel Ahmed le 3 Sep 2021
@Akira Agata thanks,Solved!!

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 3 Sep 2021
Modifié(e) : Walter Roberson le 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.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by