How to import data file as matrix and run .m file from python script?

I have a .m file that is used to run a neural network in matlab, which I locally installed on my computer. I am trying to write a python script that will cycle through a list of possible transfer and learning functions for a neural network several times. I wrote a function to open and edit a .m file, but I don’t know how to do it; 1. run the .m file from python script 2. import the necessary data for the neural network in the form of a matrix with space separators.

I have three data files that need to be imported as matrices, what does the code look like?

+1
source share
1 answer

The code for the Shai proposal may look like this

#!/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 ) 

The part between \' and \' is the MATLAB code. This can help you run MATLAB code with input arguments. Uncomment logfile = '/dev/null' if you do not need the output in the log file.

+2
source

All Articles