f

#### How to manipulate matrix dimension (2D->3D and 3D->2D)?

```1. 2D -> 3D
a = zeros(20,30);
How to create a 1X20X30 matrix b from a?

2. 3D -> 2D
b = zeros(1,20,30);
How to create a 20X30 matrix a from b?

Any reply will be highly appreciated, :)

```
 0
tw3474 (1)
6/5/2008 11:15:06 PM
comp.soft-sys.matlab 211264 articles. 26 followers. lunamoonmoon (257) is leader.

2 Replies
834 Views

Similar Articles

[PageSpeed] 19

```In article <g29s1q\$a2l\$1@fred.mathworks.com>, Tao  <tw@ualberta.ca> wrote:
>1. 2D -> 3D
>a = zeros(20,30);
>How to create a 1X20X30 matrix b from a?

b = permute(a, [3,1,2] );

Or

b = reshape(a, [1, size(a)]);

>2. 3D -> 2D
>b = zeros(1,20,30);
>How to create a 20X30 matrix a from b?

a = permute(b, [2, 3, 1]);

Or

a = reshape(b, size(b,2), []);

Or

a = squeeze(b);
--
"All is vanity."                                   -- Ecclesiastes
```
 0
roberson2 (8602)
6/5/2008 11:28:17 PM
```"Tao ":
<SNIP adding and removing dimensions...

one of the solutions

m=magic(3)
m3=reshape(m,[1,size(m)])
m2=squeeze(m)

us
```
 0
us1 (8051)
6/6/2008 12:43:03 AM