linux系统下使用sh文件传参数给matlab程序

(1)编写sh文件
程序以下面的行开始(必须在文件的第一行):
   #!/bin/sh

定义需要传递的参数,用双引号引起,参数之间使用逗号或分号隔开

【编辑好脚本后执行需要修改权限:chmod +x filename.sh,filename是sh文件的名字】

(2)举例:sh文件传递文件夹路径给matlab程序,matlab读取图片后将其转为灰度图存储。

路径‘/home/sjxy/hello/image/’下的图片。
hello.sh文件:
#!/bin/bash
imagepath='/home/sjxy/hello/image/'
/usr/local/MATLAB/R2014b/bin/matlab -nodesktop -nosplash -r "impath='$imagepath'",</home/sjxy/hello/imageread.m> /home/sjxy/hello/bb.out &
需要传递的图片路径为imagepath,matlab中使用impath接收该路径
修改hello.sh文件权限:chmod +x hello.sh
【/usr/local/MATLAB/R2014b/bin/matlab 是matlab的路径】
【不启动图形界面运行matlab:matlab -nodesktop -nosplash】
【在命令行直接运行matlab需要使用-r选项:matlab -nodesktop -nosplash -r </path/filename.m> /path/bb.out &】   
   Matlab程序:                       
I=imread(fullfile(impath,'1.jpg'));  %-- load the image
G=rgb2gray(I);
imwrite(G,[impath,'gray.jpg']); %-- save gray image
运行hello.sh: ./hello.sh       [./表示在当前目录下查找文件]
结果:

生成bb.out文件,指定路径下存储了灰度图。

传递多个参数:

sh文件:

#!/bin/bash

imagepath='/home/sjxy/hello/image/'

imagepath2='/home/sjxy/hello/im/'

/usr/local/MATLAB/R2014b/bin/matlab-nodesktop -nosplash -r  "impath='$imagepath',impath2='$imagepath2'",</home/sjxy/hello/imageread.m> /home/sjxy/hello/bb.out &
(或"impath='$imagepath';impath2='$imagepath2'")
matlab程序:

最新文章

  1. jQuery插件(右击事件)
  2. MySQL初始配置
  3. Windows Azure HandBook (1) IaaS相关技术
  4. 【原】css实现两端对齐的3种方法
  5. Java生成验证码小工具
  6. Linux服务器中木马(肉鸡)手工清除方法
  7. IDA*
  8. 简单竖向Tab选项卡
  9. CentOS DNS resolv重启无效的解决方法
  10. VS2015+MySql EF的配置问题
  11. Centos 修改时间地区及NTP同步北京时间
  12. 自学Zabbix3.8.4-可视化Visualisation-Slide shows
  13. C语言第二周作业----分支结构
  14. js操作中要去注意的一些问题
  15. 更新下载库update绝对详解
  16. BZOJ.4572.[SCOI2016]围棋(轮廓线DP)
  17. 前端框架VUE----导入Bootstrap以及jQuery的两种方式
  18. WebSphere隐藏版本号教程
  19. linux vi模式下基本命令和快捷键
  20. 洛谷P3437 [POI2006]TET-Tetris 3D(二维线段树 标记永久化)

热门文章

  1. python&#39;s twenty-third day for me 面向对象进阶
  2. java成神之——接口,泛型,类
  3. curl 命令参数
  4. 1 响应式页面-@media介绍,
  5. JavaScript第二节
  6. leetcode594
  7. 「小程序JAVA实战」 小程序手写属于自己的第一个demo(六)
  8. BMP格式详解
  9. Linux&amp;nbsp;ALSA声卡驱动之一:ALS…
  10. Redis搭建(五):Cluster集群搭建