Subscribe Bookmark RSS Feed

Convert Matrix to List?

pmroz

Super User

Joined:

Jun 23, 2011

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
3 REPLIES
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

Super User

Joined:

Jun 23, 2011

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

cell_list = as list (cell_matrix);
pmroz

Super User

Joined:

Jun 23, 2011

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