3

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!!

1
  • you can always write the data vectors to a file then read it inside MATLAB/Octave Commented Jan 18, 2011 at 15:00

3 Answers 3

4

..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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

If the vecotrs are not too long you can use the --eval options to write an octave command in a string.

prove.sh

#!/bin/bash

#  .... do something that processing vector1 vector2 
vector1="[1 2 3 4 5 6 7 8 10]"
vector2="[2 1 5 8 2 9 0 10 8]"

# ..... using octave to plot and image witouth prompting
octaveCommand="draw(${vector1},${vector2});"
echo "Command to exec: ${octaveCommand}"
octave -q --eval "${octaveCommand}"

draw.m

function draw(x,y)
    plot(x,y);
    print("graph.png","-dpng");

The -q option is to avoid the octave message at the startup. If you don't want the plot window to close you can use the --persist option to avoid octave to exit once the command is done but then you will need to manually end it by tipping exit in the terminal. At least it works for octave 3.2.3. To see more options you can tip "octave --help" in a terminal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.