Python output readable in Matlab
Question: I am a Python newbie and am trying to write a numpy array into format readable
in Matlab in the following format into an array [xi, yi, ti], separated by a
semi-colon.

In python, I am able to currently write it in the following form, which is a
numpy array printed on screen/written to file as [[xi yi ti]].

Here is the code:

    
    
    import math
    import random
    import numpy as np
    SPOT = []
    f = open('data_dump.txt', 'a')
    for i in range(10):
        X = random.randrange(6)
        Y = random.randrange(10)
        T = random.randrange(5)
        SPOT.append([X,Y,T])
    SPOT = np.array(SPOT)
    f.write(str(SPOT[:]))   
    f.close()
    

Please suggest how I should proceed to be able to write this data in Matlab
readable format as mentioned above. Thanks in advance!

Sree.


Answer: It is not very necessary to write your `array` into a special format. Write it
into a normal `csv` and use
[`dlmread`](http://www.mathworks.com/help/matlab/ref/dlmread.html) to open it
in `matlab`.

In `numpy` side, write your `array` using `np.savetxt('some_name.txt', aar,
delimiter=' ')`

