import numpy as np import matlab.engine # Start MATLAB engine eng = matlab.engine.start_matlab() eng.addpath('C:/Users/tomoh/Dropbox/SPECTRUM', nargout=0) # Generate some data # Generate some data with two overlapping peaks and random noise x = np.linspace(0, 100, 1000) peak1=y = 3 / (1 + ((x - 40) / (7 / 2))**2) peak2=y = 1 / (1 + ((x - 45) / (8 / 2))**2) peak3=y = 2 / (1 + ((x - 50) / (9 / 2))**2) noise = np.random.normal(0, 0.02, len(x)) # Random noise with SNR ~50 y = peak1 + peak2 + peak3 + noise # Convert x and y to MATLAB-compatible types x_matlab = matlab.double(x.tolist()) y_matlab = matlab.double(y.tolist()) data_matrix = np.array([x, y]) data_matrix_matlab = matlab.double(data_matrix.tolist()) # Call the MATLAB function and ensure the figure stays open try: eng.ipf(x_matlab,y_matlab,nargout=0) input("Press Enter after closing the figure...") except Exception as e: print(f"Error: {e}") # Quit MATLAB engine eng.quit()