how to pass folder path to custom function using MATLAB engine API for python
조회 수: 4 (최근 30일)
이전 댓글 표시
I have a funciton to load and process data in matlab, and I would like ot use it in python.
Using the matlab engine, I can call simple functions (standard and custom) that have input as double.
The problem is that when having the input a string(path folder), the funciton returns (0,0) and should be an array of many columns.
The Python code is below
Thanks in advance
import matlab.engine
import matlab
import numpy as np
eng = matlab.engine.start_matlab()
folder="D:\matlab results...." # The folder path with text files to process
Amplitudes_all=eng.import_matlab_data(folder) # function reads text files in selected folder and makes a 2D array with every file columnwise
ampsasarray=np.asarray(Amplitudes_all)
eng.quit()
댓글 수: 0
채택된 답변
Divyam
2024년 9월 9일
편집: Divyam
2024년 9월 9일
MATLAB and Python handle strings differently and to ensure that folder path being passed is handled as a string in MATLAB, convert the variable "folder" to a MATLAB string before passing it to the MATLAB function.
folderPath = matlab.string(folder)
Amplitudes_all = eng.import_matlab_data(folderPath)
If the issue still persists, ensure that the folder path is correctly formatted and log data to ensure that the MATLAB function being called is returning the correct inputs at various steps.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!