1. 在bash脚本中调用MATLAB脚本
首先定义一个脚本 get_ind.sh,这个脚本接收一个参数,并将这个参数传递给名为check的matlab脚本,写法如下:
#!/bin/bash
my_ind=$1
matlab_command="check($my_ind)"
matlab -nodisplay -r "$matlab_command; exit"
其中check.m内容为
function [ind] = check(a)
disp(['item' num2str(a)]);
ind = 10*a;
end
将get_ind.sh作为子脚本的调用方法:
for a in {1..10}
do
a=1
./get_ind.sh $a
done
2. 在bash脚本中调用PYTHON脚本
首先定义一个脚本 subscript.sh,这个脚本接收三个参数,并将这个参数传递给名为mypythonscript的python 脚本,写法如下:
#!/bin/bash
file_path=$1
x=$2
x=$3
python mypythonscript.py "$file_path" $x $y
其中mypythonscrpit.py的内容为
import sys
save_path = sys.argv[1]
x0 = float(sys.argv[2])
y0 = float(sys.argv[3])
将subscript.sh作为子脚本的调用方法:
file_dir="/home/software/"
n=10
for (( i=1; i<=$n; i++ ))
do
save_dir="${file_dir}item${i}/"
./subscript.sh "${save_dir}" $x $y
done
有点不好懂是吧,我会录个视频的