Python Forum
Saving data into .mat (Matlab Fiile)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving data into .mat (Matlab Fiile)
#1
Hi All,

I have a series of text files with data and I I have written this code below to extract only information in these 1 - 4 columns
from math import *
import sys
import csv
import numpy
import scipy.io

lines = open(sys.argv[1],'r').readlines()
lines = lines[9:]

for line in lines:
    v = line.split(' ')
    print('{} {} {} {}'.format(v[1],v[2],v[3],v[4]))
I want to save the output as .mat, and running the below command, the .mat files are not recognised in Matlab

for file in `ls *.data`

do 

basename=`echo $file | sed 's/\.[^.]*$//'`
extname=`echo $file | sed 's/[^0-9]*\([0-9]*\)\.\(.*\)/\2\1/'`

echo "Processing file: "$basename

python $HOME/dump2hammed.py $basename.data >  $extname.mat

done

exit 0
Please assist me with the right code to save as .mat

Thank you.

Just to add,

The text .data files I am reading have the following format.

ITEM: TIMESTEP
1000
ITEM: NUMBER OF ATOMS
139
ITEM: BOX BOUNDS ff ff ff
-2.5 0.5
-3 1.5
-1 1
ITEM: ATOMS id type x y z ix iy iz vx vy vz fx fy fz omegax omegay omegaz radius 
1 1 -0.0749673 0.772667 -0.466103 0 0 0 0 -2.6883 0 0 -0.135604 0 0 0 0 0.01 
2 1 -0.292972 0.843474 -0.60076 0 0 0 0 -2.41558 0 0 -0.135604 0 0 0 0 0.01 
3 1 -0.209048 0.807345 -0.677375 0 0 0 0 -2.55881 0 0 -0.135604 0 0 0 0 0.01 
4 1 -0.238869 0.804225 -0.758702 0 0 0 0 -2.57058 0 0 -0.135604 0 0 0 0 0.01 
5 1 -0.176754 0.804198 -0.652818 0 0 0 0 -2.57058 0 0 -0.135604 0 0 0 0 0.01 
So I am just interested in the type, x, y, z information, and I want the output to be in .mat

Thank you again.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Photo read matlab data pz16 1 1,429 Oct-06-2023, 11:00 PM
Last Post: snippsat
  How to search for a byte hex pattern with Joker in FIile lastyle 1 628 Jun-03-2023, 06:17 AM
Last Post: Gribouillis
  Saving data into xlxs colomwise erdemath 0 1,400 Oct-02-2021, 09:01 AM
Last Post: erdemath
  Data saving structure JosefFilosopio 0 2,117 May-04-2019, 10:48 AM
Last Post: JosefFilosopio
  Problem with saving data and loading data to mysql kirito85 4 3,905 Feb-08-2019, 10:53 AM
Last Post: kirito85
  Saving data from each row into separate txt kiton 7 11,325 Jul-05-2017, 03:04 AM
Last Post: kiton

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020