I have the following problem which I do not know how to approach:
I have a folder with four .mat files like this:
LeCroy000_000_ch1.mat
LeCroy000_000_ch2.mat
LeCroy000_001_ch1.mat
LeCroy000_001_ch2.mat
I want to load the 1st file ‘LeCroy000_000_ch1.mat’ and then I need two ‘for’ to iterate:
- first between channels ‘ch1’ to ‘ch2’
- then between measurements ‘000’ to ‘001’
My code:
from tkinter import *
from tkinter import filedialog as fd
from pathlib import Path
import os
import scipy.io
class Program:
def __init__(self, argument_1):
# Initializing main window
Main.resizable(0,0)
Main.geometry("300x150")
Main.title("Demo")
# Creating Canvas on top of main window
Canvas_One = Canvas(Main, width=300, height=150, bg='#%02x%02x%02x' % (240, 240, 240))
Canvas_One.place(x=0, y=0)
# Creating button
Demo_button = Button(Canvas_One, text="Extract data", width=10, heigh=2,command=self.load_files)
Demo_button.place(anchor='nw',x=10, y=10)
def load_files(self):
# Browsing the .mat file
self.open_files =fd.askopenfilename(filetypes=[("Matlab Workspace", "*.mat")])
# Getting the filename + extension
file = Path(self.open_files)
# Getting file's directory
modelRelPath = Path(self.open_files).parent
# Here I am lost
file_change = file.split('_')]
# Function
self.extract_data()
def extract_data(self):
# first for measurements iteration
for i in range(2):
# 2nd for channels iteration
for j in range(2):
obj_mat= scipy.io.loadmat(os.path.join(os.getcwd(),modelRelPath, file_change)))
Main = Tk()
Program(Main)
Main.mainloop()