mardi 1 octobre 2019

Store integers from a text file into variable arrays

I need to plot some coordinate of x, y in MATLAB using some text file. and I get a problem with reading it using a for loop.

I can figure it in Python but I need help in converting it in MATLAB.

This is some code in Python

   file = open("6.txt", "r")
   x = []
   y = []
   z = []
   for i in file.readlines()[::]:
       if i[0] == "(":
           jam = i.strip('()').split(",")
           x.append(float(jam[0]))
           y.append(float(jam[1]))
           jam = i.strip('()\n').split(",")
           z.append(float(jam[2]))
   '''

but in Matlab I initially start with this code

    fileID = fopen('1.txt', 'r+');
    formatSpec = '%s';
    for i = fscanf(fileID, '%s')[::]

in Python result is

x = [1.154545 1.265648 ..... 1.56849] 
Y = [1.0 1.5655 1.61662 ..... 1.0] 

Aucun commentaire:

Enregistrer un commentaire