博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux系统使用sh文件传参数给matlab程序
阅读量:4544 次
发布时间:2019-06-08

本文共 1265 字,大约阅读时间需要 4 分钟。

 

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

转载于:https://www.cnblogs.com/feiniao-carrie/p/9626090.html

你可能感兴趣的文章
[leetcode]Valid Palindrome
查看>>
LeetCode第四题,Add Two Numbers
查看>>
常见的JavaScript面试题
查看>>
mysql删除重复数据
查看>>
[DataStructure]多项式加法与乘法--A.数组存储(适用于零元系数少的多项式)
查看>>
大批量数据处理
查看>>
JavaScript笔记基础篇(三)
查看>>
第一次作业
查看>>
lwip 分析一
查看>>
写出高效优美的单片机C语言代码
查看>>
我的单元测试
查看>>
jQuery.Validate常用的一些规则
查看>>
Java 编码规范
查看>>
【SICP练习】9 练习1.15
查看>>
wireshark提取gzip格式的html
查看>>
poj2826 An Easy Problem?!
查看>>
docker swarm集群搭建
查看>>
【题解】【CTST2010】星际旅行
查看>>
综合题(交换)
查看>>
ADO.NET教程(1)初识ado.net
查看>>