beginner
beginner

Reputation: 1059

How to execute matlab function and save the output in a new file in linux?

This is the first time I'm using matlab scripts.

I have a folder "example" with some input files and matlab scripts. It looks like following:

example
   ├──input.score
   ├──input.param
   ├──input.expr
   ├──main.m
   ├──input.m
   ├──dist.m

I created a shell script test.sh to run main.m matlab script which has the function. The function name is shortmain

#!/bin/bash

#SBATCH --cpus-per-task=8
#SBATCH --mem-per-cpu=4G
#SBATCH --time=05:59:59

ml MATLAB/r2016a

matlab -nodisplay -nosplash -nojvm -r "run main.m"

My workload manager is Slurm, so I submitted the job like following:

sbatch test.sh

This had run the function present in main.m. But I want to execute this function on input files and save the output in a new file. Below is the function I want to execute on input files.

shortmain('input.expr', 'input.score', 'input.param', 'Trans')

Not sure how to use this in the shell script and save the output in new file. Any help is appreciated. thanq

Upvotes: 0

Views: 184

Answers (1)

damienfrancois
damienfrancois

Reputation: 59072

Rename main.m as shortmain.m and run

matlab -nodisplay -nosplash -nojvm -r "shortmain('input.expr', 'input.score', 'input.param', 'Trans'); exit"

Upvotes: 1

Related Questions