[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Changing the Dimension of a Matrix

**From**: |
Svante Signell |

**Subject**: |
Re: Changing the Dimension of a Matrix |

**Date**: |
Mon, 13 Sep 2010 21:28:54 +0200 |

On Mon, 2010-09-13 at 06:30 +0100, Andy Buckle wrote:
>* > Please forgive my ignorance. But is there a built-in command in Octave*
>* > that changes the dimension of a matrix? For instance, say*
>* > A = [1, 2, 3, 4, 5, 6].*
>* > Is there a command to transform A into a matrix B with two rows and*
>* > three columns directly instead of doing the following?*
>* > B(1,:)=A(1:3);*
>* > B(2,:)=A(4:6);*
>* > Thank you very much!*
>* > Sincerely,*
>* > Kwa*
>* *
>* > reshape(A,2,3)*
>* ans =*
>* *
>* 1 3 5*
>* 2 4 6*
B(1,:)=A(1:3);
B(2,:)=A(4:6);
B
B =
1 2 3
4 5 6
I had to write as follows to get the elements in correct order:
reshape(A,3,2)'
ans =
1 2 3
4 5 6