assigning array to another
2 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 5 Nov 2022
Huh? Did the poster totally change the question so that the answer is no longer meaningfull?
Jan
on 5 Nov 2022
Edited: Jan
on 5 Nov 2022
@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}
Answers (1)
Jan
on 5 Nov 2022
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 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!