필터 지우기
필터 지우기

assigning array to another

조회 수: 3 (최근 30일)
Adem Furkan Mursalli
Adem Furkan Mursalli 2022년 11월 5일
편집: Jan 2022년 11월 5일
A= [2, 4, 7, 12, 56, 34, 6, 96, 11, 26] I want to throw an array of 10 numbers into 1 different cell in subgroups of 4 numbers. When we group 4 numbers from a total of 10 numbers, there are 2 groups of 2 remaining numbers. I want to group the remaining 2 numbers with the numbers at the beginning of the array. Can you help?
  댓글 수: 3
Image Analyst
Image Analyst 2022년 11월 5일
Huh? Did the poster totally change the question so that the answer is no longer meaningfull?
Jan
Jan 2022년 11월 5일
편집: Jan 2022년 11월 5일
@Adem Furkan Mursalli: After I have spent the time for posting an answer, you have removed essential parts of the question and your comment. Now my answer in meaningless and the effort os wasted for the community. Therefore I consider your behavior as impolite. This is not a fair way to participate in a public forum, but annoying.
I more persons act like you did here, nobody would like to spent time for helping others anymore.
The text of the original question was (just for the case, that you want to delete it again):
A= [2, 4, 7, 12, 56, 34, 6, 96, 11, 26] I want to throw an array of 10 numbers into 1 different cell in subgroups of 4 numbers. When we group 4 numbers from a total of 10 numbers, there are 2 groups of 2 remaining numbers. I want to group the remaining 2 numbers with the numbers at the beginning of the array. Can you help?
And your comment to my question for clarification:
cell1={2 4 7 12}, cell2={56 34 6 96}, cell3={11 26 2 4}, cell4={7 12 56 34}, cell5={6 96 11 26}, cell6={2 4 7 12}

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

답변 (1개)

Jan
Jan 2022년 11월 5일
Maybe:
A = [2, 4, 7, 12, 56, 34, 6, 96, 11, 26];
q = mod((1:24) - 1, numel(A)) + 1;
B = A(q);
B = reshape(B, 4, [])
B = 4×6
2 56 11 7 6 2 4 34 26 12 96 4 7 6 2 56 11 7 12 96 4 34 26 12
Here the wanted subgroups are the columns of B. If you want cells:
C = num2cell(B.', 2)
C = 6×1 cell array
{[ 2 4 7 12]} {[56 34 6 96]} {[ 11 26 2 4]} {[7 12 56 34]} {[6 96 11 26]} {[ 2 4 7 12]}

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by