Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a bash script to run a matlab program in UNIX?

I have no bash scripting background. I know the basics of unix command line.

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.

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

like image 265
Shaayaan Sayed Avatar asked Nov 19 '25 18:11

Shaayaan Sayed


2 Answers

Assume that the matlab command is in your path (for more info, See the documentation )

Supposing you just wanted to get all of the BMP's (you didn't specify file type), you can use a simple bash loop:

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.

like image 195
SheetJS Avatar answered Nov 21 '25 09:11

SheetJS


You need

  • one command what produces list of images one per line. Call it as list_images, or a filename 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

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.

EDIT for finding prj files in the curent directory

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".

like image 45
jm666 Avatar answered Nov 21 '25 07:11

jm666



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!