Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Reshape the array along the reverse dimensions

Kevin Dong:


>> A = [ 1 2 3 3 4 5 5 6 7 7 8 9 ];
>>
>> B = reshape(A, 2, 2, 3)

B(:,:,1) =

1 3
2 3


B(:,:,2) =

4 5
5 6


B(:,:,3) =

7 8
7 9

Since reshape can only change the size of the given array in the way of preserving the linear indices, however I would like to reshape the array along the reverse dimensions.

For example, convert A into


>> C = reverse-reshape(A, 2, 2, 3) % not required to be only one function

C(:,:,1) =

1 3
5 7

C(:,:,2) =

2 4
6 8

C(:,:,3) =

3 5
7 9

Is there any better method than writing loops and fill numbers one by one in version R2017b?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Reshape the array along the reverse dimensions

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×