turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-16-2011 04:24 PM

Hi everyone!

Maybe you could help me with my latest obstacle I've encountered with IML. Do you happen to know how to convert a vector into a matrix?

Here is a little example to give you a better idea:

Given:

Vector n (1000x1)

Goal:

Convert vector n into a 50x20 matrix m. The first column of matrix m should be equal to the first 50 elements of vector n. The second column should be equal to the next 50 elements and so on.

It would be great if you had a solution for this problem... Thanks a million!!!

Accepted Solutions

Solution

11-16-2011
04:36 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-16-2011 04:36 PM

Use the SHAPE function.

A blog article on reshaping matrices is here: http://blogs.sas.com/content/iml/2010/10/11/how-can-you-reshape-a-matrix/

The SHAPE function arranges the elements rowwise, so the first ROW of m contains the first consecutive elements:

v = 1:1000;

w = shape(v, 20, 50); /* w is 20 x 50 */

To get the data in column-wise order, transpose w:

m = T(w); /* m is 50 x 20 */

Rick

Statistical programming blog: http://blogs.sas.com/content/iml

All Replies

Solution

11-16-2011
04:36 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-16-2011 04:36 PM

Use the SHAPE function.

A blog article on reshaping matrices is here: http://blogs.sas.com/content/iml/2010/10/11/how-can-you-reshape-a-matrix/

The SHAPE function arranges the elements rowwise, so the first ROW of m contains the first consecutive elements:

v = 1:1000;

w = shape(v, 20, 50); /* w is 20 x 50 */

To get the data in column-wise order, transpose w:

m = T(w); /* m is 50 x 20 */

Rick

Statistical programming blog: http://blogs.sas.com/content/iml

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-16-2011 05:24 PM

Wow... that went fast! Thank you so much Rick!!!