Skip to content

Commit f7e3a0c

Browse files
committed
refactor matlab.py
1 parent 3a4b922 commit f7e3a0c

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

ratapi/utils/matlab.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@
1010
from ..wrappers import MatlabWrapper
1111

1212
RUNNER = """function executeRAT()
13+
14+
cur_dir = pwd;
15+
cd('{rat_path}');
16+
addPaths;
17+
cd(cur_dir);
18+
1319
project = jsonToProject('{project}');
1420
controls = jsonToControls('{control}');
21+
for i=1:project.customFile.rowCount
22+
addpath(project.customFile.varTable{{i, 5}});
23+
end
1524
[project, results] = RAT(project, controls);
1625
1726
projectToJson(project, '{project}');
@@ -36,7 +45,6 @@ def run_matlab_directly(project, controls, matlab_rat_path):
3645
raise ImportError(MatlabWrapper.loader_error_message) from None
3746

3847
engine = MatlabWrapper.loader.result()
39-
cur_dir = os.getcwd()
4048

4149
with tempfile.TemporaryDirectory() as tmp:
4250
project_file = Path(tmp, "project.json")
@@ -45,22 +53,17 @@ def run_matlab_directly(project, controls, matlab_rat_path):
4553
runner_file = Path(tmp, "executeRAT.m")
4654

4755
with open(runner_file, "w") as f:
48-
f.write(RUNNER.format(project=project_file, control=control_file, result=result_file))
56+
f.write(RUNNER.format(project=project_file, control=control_file, result=result_file,
57+
rat_path=matlab_rat_path))
4958

5059
with warnings.catch_warnings(): # Avoid warning about relative paths
5160
warnings.simplefilter("ignore")
5261
project.save(project_file)
5362
controls.save(control_file)
54-
55-
engine.cd(matlab_rat_path, nargout=0)
56-
engine.eval("addPaths", nargout=0)
57-
engine.cd(cur_dir, nargout=0)
58-
63+
5964
engine.addpath(tmp, nargout=0)
60-
for file in project.custom_files:
61-
engine.addpath(str(file.path), nargout=0)
62-
6365
engine.executeRAT(nargout=0)
66+
engine.rmpath(tmp, nargout=0)
6467

6568
project = Project.load(project_file)
6669
results = Results.load(result_file)

0 commit comments

Comments
 (0)