cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
pmroz
Super User

Convert Matrix to List?

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
1 ACCEPTED SOLUTION

Accepted Solutions
mpb
mpb
Level VII

Re: Convert Matrix to List?

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

cell_list = as list (cell_matrix);

View solution in original post

3 REPLIES 3

Re: Convert Matrix to List?

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.
mpb
mpb
Level VII

Re: Convert Matrix to List?

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

cell_list = as list (cell_matrix);
pmroz
Super User

Re: Convert Matrix to List?

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