# HP Forums

Full Version: mat2list command
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to convert a one-dimensional matrix (a vector) to a list.

The cataloque menu provides a function called "mat2list" which concatenates the rows of a matrix to just a single row. However, this is still a matrix object with square brackets, e.g. of type "4", which is not what I want (curly braces, type "6").
In contrast the oposite function "list2mat" works as expected.

Is there some other function for this purpose, or maybe some "type conversion"?

Thanks,
Thomas
Assign it to a "L" variable:

L3:=mat2list([[1,2],[3,4]])

Not very elegant, indeed.

Why not use some recursion in a CAS function?

lc([a b c]) returns {a b c}

I like functional languages! BTW this is a classic example of tail recursion. Many functional languages translate it to a loop. It will be nice to know which is the CAS behavior.
Try convert(vector,23)
23 is the subtype of HP lists (Xcas does not make a difference between vectors and lists), 0 is for normal lists, 1 for sequences, 2 for sets.
And the CAS does not try to convert your code to a loop. It is interpreted like it was entered.
(02-18-2014 08:01 AM)parisse Wrote: [ -> ]Try convert(vector,23)
23 is the subtype of HP lists (Xcas does not make a difference between vectors and lists), 0 is for normal lists, 1 for sequences, 2 for sets.

That's what I was looking for! Thanks!

It's just a bit confusing that CONVERT in Home view means Unit conversion. So one has to use CAS.convert instead...
I'm modifying mat2list to return a HP list.
The same CAS convert command performs list subtype conversion, unit conversion and also some rewriting commands (and in that case you can use STO> as a shortcut, like 1_m Sto> _cm or x^4-1 Sto> * )
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :