Writing a single list of numbers to a .m (matlab) file

Chris Rebert clp2 at rebertia.com
Fri Jul 17 16:55:20 EDT 2009


On Fri, Jul 17, 2009 at 11:06 AM, Hanna Michelsen<hannarosie at gmail.com> wrote:
> Hi,
>
> I was wondering if I could get some suggestions on how to write a single
> list of numbers to a .m file (for matlab) so that I can create a matlab
> vector out of the list of numbers from my python program. I have been using
> a csv writer to create .m files from lists of lists, but I'm not sure how to
> write just a single list to the file. (if I use the same code I've been
> using, I get an error: csv.Error sequence expected)

You didn't provide any code, but since csv is probably overkill anyway:

m_file.write("[" + " ".join(str(num) for num in numbers) + "]\n")

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list