Skip to content

Commit c841edf

Browse files
committed
script to convert .mat files to txt
1 parent 5e7eef7 commit c841edf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

matconverter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
import scipy.io
3+
4+
def mat_to_txt(mat_file, txt_file):
5+
# Cargar el archivo .mat
6+
data = scipy.io.loadmat(mat_file)
7+
8+
# Abrir el archivo de salida
9+
with open(txt_file, "w") as f:
10+
for key, value in data.items():
11+
# Saltar metadatos de MATLAB
12+
if key.startswith("__"):
13+
continue
14+
f.write(f"Variable: {key}\n")
15+
f.write(f"Contenido:\n{value}\n\n")
16+
17+
if __name__ == "__main__":
18+
if len(sys.argv) != 3:
19+
print("Uso: python mat_to_txt.py entrada.mat salida.txt")
20+
else:
21+
mat_file = sys.argv[1]
22+
txt_file = sys.argv[2]
23+
mat_to_txt(mat_file, txt_file)
24+
print(f"Archivo {mat_file} convertido en {txt_file}")

0 commit comments

Comments
 (0)