I have a workspace A with value 81536x10 double. I want to take create new workspace from workspace A with row 1 to 112, 225 to 336, 449 to 560 and so on.

 채택된 답변

Jos (10584)
Jos (10584) 2019년 4월 25일

1 개 추천

ix = [0:224:81563]' + 1:112 ; % calculate row indices
ix(ix>size(A,1)) = [] % remove row indices that are too larger
A2 = A(ix, :) % a single array
Alternatively, you can store each section in a cell array
A3 = arrayfun(@(k) A(k:k+111, :), 1:224:81563, 'un', 0) % no check of indices

댓글 수: 5

Setiadi Suriana
Setiadi Suriana 2019년 4월 25일
Thank you for answer, but from that code, i only can get row 1-112 only but i want another rows 225 to 336, 449 to 560 and so on (until 81536)
Jos (10584)
Jos (10584) 2019년 4월 25일
My code does that doesn't it? I suggest you come up with a smaller example, giving the input and expected output, for instance for a 10-by-2 array A.
Setiadi Suriana
Setiadi Suriana 2019년 4월 25일
I tried with 6 by 2 array A and want to obtain values from rows 1-2 and 5-6 but the output only rows 1-2
Oh, this might be related to your version of ML.
A = randi(100,6,2)
ix = bsxfun(@plus,[0:1]', 1:4:size(A,1))
A(ix,:)
should return rows 1-2 and rows 5-6 of A
Setiadi Suriana
Setiadi Suriana 2019년 4월 26일
Thank you, now it is working

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

2019년 4월 25일

댓글:

2019년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by