Importing a list of tuples genrated in python to MATLAB

I have a list of tuples generated in python. The list is save in a text file and loaded in MATLAB.
[(2, 4), (2, 12), (2, 8)]
I'd like to import the list in MATLAB as a matrix?
Any suggestion on how this can be done?

Answers (1)

matrix=load('mytext.txt')

9 Comments

It returns
Unknown text on line number 1 of ASCII file list.txt
"[(2".
Text file contains:
[(2, 4), (2, 12), (2, 8)]
I'd like to import it as [2,4;2,12;2,8]
From what I understand, the list of tuples in MATLAB is written as
[[2,3],[3,4]]
But, the python output of list of tuples is
[(2, 4), (2, 12)]
Sorry, I am still not sure about how to use
py.tuple
while importing the data from text file
See the example below:
>> py.list({py.list([1,2]),py.list([3,4])})
ans =
Python list with no properties.
[[1.0, 2.0], [3.0, 4.0]]
>>
The problem is I am not able to import the file using load function

Sign in to comment.

Asked:

on 2 Dec 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!