3

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

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

Sorry for being ambiguous. The input files are in .prj format. I have them all stored in a directory. I really just need the script to pass in the file names as a parameter to my matlab function. In your answer above, I'm not understanding where you actually read the file names from the directory.

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.