问题描述
我有一个.m文件,该文件用于在matlab中运行神经网络,该文件已本地安装在计算机上.我正在尝试编写一个Python脚本,该脚本将多次遍历神经网络可能的传递和训练功能的列表.我已经编写了一个打开和编辑.m文件的功能,但是我不知道如何操作. 1.从python脚本运行.m文件.2.将神经网络所需的数据导入为空格分隔的矩阵.
I have a .m file that is used to run a neural network in matlab, which I have locally installed on my computer. I am trying to write a python script that will loop through a list of possible transfer and training functions for the neural network multiple times. I've written a function to open and edit the .m file, but I don't know how to; 1. run the .m file from the python script 2. import the necessary data for the neural network as a space delimited matrix.
我有三个需要作为矩阵导入的数据文件,代码是什么样的?
I have three data files that need to be imported as matrices, what would the code look like?
推荐答案
看起来像这样
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
your_dir = '/path/to/your/mfile'
your_mfile = 'name_of_mfile_without.m'
logfile = '/path/to/save/matlab/standard_out.txt'
# logfile = '/dev/null'
transfer_functions = ['func_1','func_2']
for f in transfer_functions:
os.system(' matlab -nodesktop -nosplash -nodisplay -r \' '
' addpath ' + your_dir + ' ; '
your_mfile + ' ' + f + ' ; '
' exit ; \' '
' > ' + logfile )
\'
和\'
之间的部分是MATLAB代码.这可以帮助您使用输入参数运行MATLAB代码.如果不需要日志文件中的输出,请取消注释logfile = '/dev/null'
.
The part between \'
and \'
is MATLAB code. This could help you to run your MATLAB code with input arguments. Uncomment logfile = '/dev/null'
, if you do not need the output in the logfile.
这篇关于如何将数据文件作为矩阵导入并从python脚本运行.m文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!