How to change array format - change row number and column number, but have all the data as before
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am interested in following if I put as an example;
I have an array A;
1 1 1 1
1 1 1 1
1 1 1 1
2 2 2 2
2 2 2 2
2 2 2 2
3 3 3 3
3 3 3 3
3 3 3 3
Now I would like to change this to array B which would look like;
1 1 1 1 2 2 2 2 3 3 3 3
1 1 1 1 2 2 2 2 3 3 3 3
1 1 1 1 2 2 2 2 3 3 3 3
How can I do this type of thing on matlab? The array A can have much more sets of data, and the code must go through each row of A until there is no more data.
Thanks a lot in advance! Sara
0 个评论
采纳的回答
Stephen23
2018-6-1
编辑:Stephen23
2018-6-1
Depending on the required element order, (along 2nd dim first):
B = reshape(A.',3,[])
or (along 1st dim first):
B = reshape(permute(reshape(A,3,[],4),[1,3,2]),3,[])
or (along 1st dim first):
cell2mat(mat2cell(A,[3,3,3],4).')
4 个评论
Stephen23
2018-6-1
编辑:Stephen23
2018-6-1
>> reshape(permute(reshape(A.',size(A,2),2,[]),[2,1,3]),2,[])
ans =
0.547009 0.744693 0.686775 0.368485 0.780227 0.929386 0.486792 0.446784 0.508509 0.817628 0.644318 0.811580 0.350727 0.875943 0.622475
0.296321 0.188955 0.183511 0.625619 0.081126 0.775713 0.435859 0.306349 0.510772 0.794831 0.378609 0.532826 0.939002 0.550156 0.587045
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!