vera_kkk
vera_kkk

Reputation: 47

How to run Matlab batch script and save the results

#!/bin/bash
###########################
#
#PBS -l nodes=1:ppn=12
#PBS -l walltime=00:30:00

XXXXXXXXXx and below is my script details about running matlab I want to save the results from the trial.m however it does not work.

export JOBID=`echo "${PBS_JOBID}" | cut -d'.' -f1`
cd ${PBS_O_WORKDIR}
module load matlab/R2017b
matlab
trial.m

My script name: trial.m How to save the results from trial.m to my environment? In my trial.m matlab file, I have the following codes to display my results, does this work? betas and values are two vector of numbers

disp(betas); 
disp(values);
save('parameters.mat','betas','values');

In addition, trial.m needs to call external functions that I saved in the same file, can it call automatically?

Upvotes: 2

Views: 862

Answers (1)

Azim J
Azim J

Reputation: 8290

Invoke MATLAB and execute trial.m via the following command:

matlab -r trial -logfile logfile.log -nodisplay -nosplash

Make sure trial.m exits MATLAB when it finishes, to continue executing any post-processing steps. You should also suppress the MATLAB GUI and Splash screens since the script is running non-interactively. Also make sure that trial.m forces MATLAB to exit by using the exit command.

Save the results of trial.m to the environment by calling the save function to create a .MAT file. NOTE: To access the file using other software, save in CSV format by calling csvwrite.

csvwrite('betas.csv',betas);
csvwrite('values.csv',values);

MATLAB Alternative to Bash

Alternatively you could use MATLAB's parrallel computing toolbox to submit the job. In this case you no longer need the bash script. However, you would need to modify your MATLAB files to handle the job submission to the cluster (here).

Upvotes: 4

Related Questions