How do I import a data file as a matrix and run a .m file from a python script?

后端 未结 1 911
挽巷
挽巷 2021-01-23 17:57

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 lis

相关标签:
1条回答
  • 2021-01-23 18:54

    Code for the suggestion by Shai could 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 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.

    0 讨论(0)
提交回复
热议问题