turn on suggestions

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

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Convert Matrix to List?

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
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 29, 2010 7:47 AM
(3044 views)

Hi JMP folks,

I can do this in a loop, but is there a simple one-liner to convert a one-dimensional matrix to a list? Something like:

cell_list = getmatrixaslist(cell_matrix);

Additional bonus question: is there an equivalent to the list LOC function for a matrix? I need to locate all rows in a matrix with a certain value. The LOC function does this for lists, but for matrices it finds all elements equal to 0.

Thanks!

Peter

I can do this in a loop, but is there a simple one-liner to convert a one-dimensional matrix to a list? Something like:

cell_list = getmatrixaslist(cell_matrix);

Additional bonus question: is there an equivalent to the list LOC function for a matrix? I need to locate all rows in a matrix with a certain value. The LOC function does this for lists, but for matrices it finds all elements equal to 0.

Thanks!

Peter

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 29, 2010 11:50 AM
(4795 views)

Here's the syntax for converting a 1D matrix to a list:

cell_list = as list (cell_matrix);

cell_list = as list (cell_matrix);

3 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 29, 2010 10:39 AM
(2902 views)

You can use the LOC function to locate all rows of a matrix that are equal to a value. Consider the following example:

If my matrix is

m=[1,3,3,6,7,1,3,9]

then use the following to locate all rows of that matrix that are equal to 3:

loc(m==3)

This returns the following result

[2,3,7]

which is a matrix of row numbers of m that are equal to 3.

If you leave off the loc function and just use m==3, then you get a matrix of 1's and 0's, with a 1 indicating the value is equal to 3.

If my matrix is

m=[1,3,3,6,7,1,3,9]

then use the following to locate all rows of that matrix that are equal to 3:

loc(m==3)

This returns the following result

[2,3,7]

which is a matrix of row numbers of m that are equal to 3.

If you leave off the loc function and just use m==3, then you get a matrix of 1's and 0's, with a 1 indicating the value is equal to 3.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 29, 2010 11:50 AM
(4796 views)

Here's the syntax for converting a 1D matrix to a list:

cell_list = as list (cell_matrix);

cell_list = as list (cell_matrix);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 29, 2010 12:06 PM
(2902 views)

Thank you very much for your responses. It's easy when you know how!