• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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程序:

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi七个版本发布时间:2022-07-18
下一篇:
Delphi简介发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap