Skip to content

Instantly share code, notes, and snippets.

@IamPhytan
Last active June 29, 2019 02:02
Show Gist options
  • Select an option

  • Save IamPhytan/d0dcc8535d775a33cb10f4a2ec4b7874 to your computer and use it in GitHub Desktop.

Select an option

Save IamPhytan/d0dcc8535d775a33cb10f4a2ec4b7874 to your computer and use it in GitHub Desktop.
Batch file to run MATLAB files in a terminal or in the command prompt
:: Run MATLAB scripts in CMD
:: Usage Examples
:: 'mat' is the name of my batch file
:: mat myScript.m
@echo off
:: Get filename by removing extension
set filename=%1
set filename=%filename:~0, -2%
:: Output filename
set out_file="output.txt"
:: Run MATLAB
"C:\Program Files\MATLAB\R2018a\bin\matlab.exe" -nosplash -nodesktop -wait -r "diary('%out_file%'); %filename%; diary off; exit"
:: Show content of output file and delete it
type %out_file%
del %out_file%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment