Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Parameters _ Shell Script - Octave Script

How can i pass two parameters (number vectors) from a Shell Script to a Octave Script ??

That's the idea..

In "prove.sh"

 #!/bin/bash

 .... do something that processing vector1 vector2 

./draw.m Vector1 Vector2

In "draw.m"


 plot(Vector1, Vector2)

Thank you!!

like image 796
kafka Avatar asked Jun 20 '26 21:06

kafka


2 Answers

..And, if you allow me, i add a small variation for a Octave Script since the former was in Matlab ;)

Arrays.sh

#!/bin/bash
# create random data
for i in {1..10}; do v1[$i]=$RANDOM; done
for i in {1..10}; do v2[$i]=$RANDOM; done

# save data to file
echo ${v1[@]} > file.txt
echo ${v2[@]} >> file.txt

# call OCTAVE script
octave draw.m

Draw.m

load ("-ascii", "file.txt")
plot(file(1,:), file(2,:))      %# if you want see the graphic
print('figure.ps', '-deps')     %# save the result of 'plot' into a postscript file
exit
like image 159
Zany Avatar answered Jun 23 '26 12:06

Zany


As I mentioned in the comments above, you can simply save the data to a file then call the MATLAB/Octave script which will in turn load the data from file. Example:

arrays.sh

#!/bin/bash

# create random data
v1=$(seq 1 10)
for i in {1..10}; do v2[$i]=$RANDOM; done

# save data to file
echo $v1 > file.txt
echo ${v2[@]} >> file.txt

# call MATLAB script
matlab -nodesktop -nojvm -nosplash -r "draw_data; quit" &

draw_data.m

load('/path/to/file.txt','-ascii')   %# load data
plot(file(1,:), file(2,:), 'r')      %# plot
saveas(gcf, 'fig.eps', 'psc2')       %# save figure as EPS file
exit
like image 25
Amro Avatar answered Jun 23 '26 10:06

Amro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!