shell传参给matlab问题解决办法

以前须要经过shell脚本传参给matlab程序,可是遇到一些问题,现将我遇到的问题分享出来,给遇到一样问题的人一些借鉴。node

shell部分脚本Execl.sh:python

/usr/bin/python /home/shk/IPMProduct.py $1
cd /home/shk/ && /usr/local/MATLAB/R2015b/bin/matlab -nodesktop -nosplash -r "sDate='$1';test;quit"shell

ps:app

1./usr/bin/python /home/shk/IPMProduct.py $1。为调用Python程序,IPMProduct.py为python程序名,$1为shell脚本接收的第一个参数ui

2.cd /home/shk/ && /usr/local/MATLAB/R2015b/bin/matlab -nodesktop -nosplash -r "sDate='$1';test;quit"。为调用matlab程序,test为matlab程序名,sDate='$1'为传入matlab的字符型参数,matlab中用一样的变量sDate接收。quit为执行完test程序后退出matlab环境。-nodesktop -nosplash -r这几个参数见上一篇文档说明。文档

 

matlab程序部分代码 test.m:直接使用sDate变量便可it

%clc;
%close all;
%clear;
filedir=['/gds/',sDate,'/'];
filenameT = dir(fullfile(filedir,'*_030KM_MS_UDS.HDF'));
filenameArr = char({filenameT.name}) 
 
fileoutdir=['/gds/DATA/',sDate,'/'];
[fileoutnameT]=mapplot(filedir,filenameArr,F107,fileoutdir);
 
题外话:以前因为matlab中clc; close all;clear;没有注释掉,每次传进来的参数值都被清理掉了,sDate没有获取数值,致使MATLAB程序错误。注释掉以后程序正常运行。真的是,这个问题困扰了我很久,一直觉得是shell脚本中传参给matlab的程序没写对,查了好多资料,后来才发现是由于进入matla后参数都被清理掉了。
相关文章
相关标签/搜索