How can i pass two parameters (number vectors) from a Shell Script to a Octave Script ??
That's the idea..
#!/bin/bash
.... do something that processing vector1 vector2
./draw.m Vector1 Vector2
In "draw.m"
plot(Vector1, Vector2)
Thank you!!
..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
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:
#!/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" &
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With