How to export array elements?

조회 수: 2 (최근 30일)
Rubel Ahmed
Rubel Ahmed 2021년 9월 2일
댓글: Rubel Ahmed 2021년 9월 3일
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