assigning array to another

3 次查看(过去 30 天)
Adem Furkan Mursalli
编辑: 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