编写 bash 脚本以在 UNIX 中运行 matlab 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17894676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Writing a bash script to run a matlab program in UNIX?
提问by Shaayaan Sayed
I have no bash scripting background. I know the basics of unix command line.
我没有 bash 脚本背景。我知道unix命令行的基础知识。
I have a matlab script that takes in an matrix image as input. I have a bunch of images in a file. I need the bash script to call the matlab program and feed every single image in the file as input to the program one by one.
我有一个将矩阵图像作为输入的 matlab 脚本。我在一个文件中有一堆图像。我需要 bash 脚本来调用 matlab 程序并将文件中的每个图像作为程序的输入一一输入。
If you want to write it go ahead that would be great. All I'm asking is for someone to direct me to exactly what I should look into.
如果你想写它,那就太好了。我所要求的只是有人指导我确切地了解我应该研究的内容。
Thanks
谢谢
回答by SheetJS
Assume that the matlab
command is in your path (for more info, See the documentation)
假设该matlab
命令在您的路径中(有关更多信息,请参阅文档)
Supposing you just wanted to get all of the BMP's (you didn't specify file type), you can use a simple bash loop:
假设您只想获取所有 BMP(您没有指定文件类型),您可以使用一个简单的 bash 循环:
for f in *.BMP; do
matlab -nosplash -nodisplay -nojvm -r "my_command('$f'),quit()"
done
The -nosplash
, -nodisplay
, and -nojvm
ensure that the GUI isn't triggered, and the -r
instructs matlab to run the command. The ,quit()
at the end ensures that matlab quits after running.
的-nosplash
,-nodisplay
以及-nojvm
确保GUI不会被触发,并-r
指示MATLAB来运行该命令。在,quit()
运行后,在年底确保MATLAB退出。
回答by jm666
You need
你需要
- one command what produces list of images one per line. Call it as
list_images
, or afilename
what contains the list of images - one cycle
- command, what reads the images
- one variable (calling it "image_name")
- comamnd to run matlab
- place, here the output should go
- 一个命令产生每行一个图像列表。将其称为
list_images
,或filename
包含图像列表的内容 - 一个周期
- 命令,读取图像的内容
- 一个变量(称为“image_name”)
- 命令运行matlab
- 地方,这里的输出应该去
Something like:
就像是:
list_images | while read image_name
do
matlab_command "$image_name" > "$image_name.output"
done
or better
或更好
while read image_name
do
matlab_command "$image_name" > "$image_name.output"
done < filename_with_images.txt
Not really understand what you mean with the have amatrix images in a file
, post an example of your input.
不太明白您对 的意思have amatrix images in a file
,请发布您输入的示例。
EDITfor finding prj
files in the curent directory
编辑以prj
在当前目录中查找文件
find . -maxdepth 0 -name \*.prj -print0 | while IFS= read -r -d '' image_name
do
matlab_command "$image_name" > "$image_name.output"
done
Google for "bash tutorial".
谷歌搜索“bash 教程”。