assigning array to another
1 次查看(过去 30 天)
显示 更早的评论
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
2022-11-5
Huh? Did the poster totally change the question so that the answer is no longer meaningfull?
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
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, [])
Here the wanted subgroups are the columns of B. If you want cells:
C = num2cell(B.', 2)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!