필터 지우기
필터 지우기

How to add a .mat file (including the file path) to a specific location in a Python script and save this Python script using matlab?

조회 수: 3 (최근 30일)
Is it possible to add a .mat file location to a specific location in a Python script and save this Python script using MATLAB

채택된 답변

Kenny Shu
Kenny Shu 2018년 8월 28일
You can write directly to the Python script using "fprintf":
replaceLine = 2
fid = fopen('mypyfile.py', 'r+');
for k=1:(replaceLine-1);
fgetl(fid);
end
fseek(fid, 0, 'cof');
fprintf(fid,'print("%s")','myMAT.mat')
fclose(fid)
Refer to the following link for additional information on writing data to text files:
Consider writing the MAT file location to an intermediate medium (such as a text file or database) in MATLAB and reading from that medium in Python.
  댓글 수: 1
sachin k p
sachin k p 2018년 9월 2일
편집: sachin k p 2018년 9월 2일
fgetl(fid) is not taking me to the correct line to be replaced. It seems fgetl(fid) is also reading space in between. How to remove this spaces and just read the lines. This is the output I am getting eg:
tline =
file1
tline =
''
tline =
file2
tline =
''

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by