Jul-26-2021, 03:55 PM
(This post was last modified: Jul-26-2021, 04:05 PM by Yoriz.
Edit Reason: Added code tags
)
I have a code which is converting between file types. I have 10 .vtp files and I am converting these to .mat files.
My code works, but it only saves the .mat file of the last iteration of the loop, so instead of having 10 files I just get one.
Could anybody help me with this?
My code works, but it only saves the .mat file of the last iteration of the loop, so instead of having 10 files I just get one.
Could anybody help me with this?
import vtk from vtk.util.numpy_support import vtk_to_numpy import numpy as np import scipy.io as sio c = 0 out = {} starts = 0 ends = 11 for i in range(starts,ends): # File to read fname = 'RP_DATA_%04.0f.vtp'%i # --- read a vtp file --- points = vtk.vtkXMLPolyDataReader() points.SetFileName(fname) points.Update() # print the arrays out data = points.GetOutput() point_data = data.GetPointData() import inspect print(inspect.getdoc(point_data)) vel = vtk_to_numpy(point_data.GetAbstractArray('Velocity')) points = vtk_to_numpy(data.GetPoints().GetData()) c = c+1; name = f"out_{c}.mat" sio.savemat(name, {'vel':vel, 'points':points}) print(i)