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

linux系统使用sh文件传参数给matlab程序的更多相关文章

  1. 关于Linux系统清理/tmp/文件夹的原理

    转自:http://www.opsers.org/base/clean-up-on-the-linux-system-tmp-folder-you-may-want-to-know.html 我们知道 ...

  2. linux下执行.sh文件的方法和语法

    linux下执行.sh文件的方法    .sh文件就是文本文件,如果要执行,需要使用chmod a+x xxx.sh来给可执行权限.       是bash脚本么   可以用touch test.sh ...

  3. linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体[转]

    linux 系统获得当前文件夹下存在的所有文件 scandir函数和struct dirent **namelist结构体 1.引用头文件#include<dirent.h> struct ...

  4. linux系统下修改文件夹目录权限

    linux系统下修改文件夹目录权限 文件夹权限问题 Linux.Fedora.Ubuntu修改文件.文件夹权限的方法差不多.很多人开始接触Linux时都很头痛Linux的文件权限问题.这里告诉大家如何 ...

  5. 使用WinSCP在Windows和Linux系统之间传输文件

    小梅哥编写,未经许可,严禁用于任何商业用途 2018年6月30日 在日常SoC开发中,我们经常需要在Windows和Linux系统之间传输文件,例如在Windows系统上的DS-5集成开发环境中编写好 ...

  6. linux系统加快大文件的写入速度

    linux系统加快大文件的写入速度 setvbuf进行优化内存IO

  7. Linux下执行.sh文件

    Linux下执行.sh文件有两种情况: 一.直接./加上文件名.sh,如运行hello.sh为./hello.sh[hello.sh必须有x权限] 二.直接sh 加上文件名.sh,如运行hello.s ...

  8. C# 如何执行bat文件 传参数

    C# 如何执行bat文件 传参数 分类: C# basic 2011-04-25 18:55 3972人阅读 评论(0) 收藏 举报 c#stringpathoutput Process p = ne ...

  9. linux 下执行.sh文件总是提示permission denied

      linux 下执行.sh文件总是提示permission denied 如果你是root登陆的话(不是的话,切换到root用户,对*.sh赋可执行的权限) chmod 777 *.sh or ch ...

随机推荐

  1. yield-from示例

    #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time    : 2018/6/20 9:13# @File    : yield_from11.py fro ...

  2. Cocos2D中的内部函数

    virtual bool isVisible();    // 是否可见    virtual void setVisible(bool visible);      // 设置是否可见    boo ...

  3. get与post两种方式的优缺点

    get: get是从服务器上获取数据,post是向服务器传送数据: get传送的数据量较小,不能大于2KB.post传送的数据量较大,一般被默认为不受限制.但理论上,IIS4中最大量为80KB,IIS ...

  4. C语言中字符数据的输入和输出

    字符的输出 C语言中使用putchar函数来输出字符数据 #include <stdio.h> int main() { char a,b,c,d; //定义字符变量a,b,c,d a = ...

  5. jQuery.prop() 与attr()

    1.attr()是jQuery 1.0版本就有的函数,prop()是jQuery 1.6版本新增的函数.毫无疑问,在1.6之前,你只能使用attr()函数:1.6及以后版本,你可以根据实际需要选择对应 ...

  6. spring 3.1.13中新增的util @value注解,给类或方法注入值

    在spring 3.0以上版本中,可以通过使用@value,对一些如xxx.properties文件 ,进行键值对的注入,例子如下: 一.类变量注入 1 首先在applicationContext.x ...

  7. 【HDU4307】Matrix

    本篇博客基本全篇转自https://www.cnblogs.com/staginner/archive/2012/08/13/2636826.html,太强啦ORZ 题意 A是个1*n的矩阵,每个元素 ...

  8. Linux修复MBR扇区故障

    给虚拟机增加一块硬盘,用于备份mbr的信息 fdisk -l 查看硬盘系统是否认识 fdisk /dev/sdb 进行分区 fdisk -l 查看分区是否出来 mkfs -t ext4 /dev/sb ...

  9. mysql 基本操作 alter

    查看数据库 show  databases; 新建数据库 命令 create database 库名字. 选择数据库 use  2016test; 创建表:create table 表名(字段1,2, ...

  10. AntD02 Table组件的使用

    1 前提准备 1.1 创建一个angular项目 1.2 将 Ant Design 整合到 Angular 项目中 1.3 官方文档 点击前往 2 简单使用 <nz-table #rowSele ...