Created
June 18, 2013 14:19
-
-
Save dgleich/5805712 to your computer and use it in GitHub Desktop.
Command to call Matlab as a script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
2 | |
3 | |
4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function load_file(filename) | |
f = load(filename); | |
fprintf('%i\n',sum(f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This version shows additional error output | |
script=`basename "$1" .m` # this will return $1 unless it ends with .m | |
if [ "$script" = "$1" ]; then | |
cmdterm=, | |
else | |
cmdterm=\; | |
fi; | |
shift # remove the first argument | |
args="$@" | |
argsq=`echo $args | tr '"' "'"` | |
matlab -nodisplay -r "disp('BEGIN>>'); try, $script $argsq $cmdterm catch me, fprintf(2,getReport(me)); exit(1); end, exit(0)" -nosplash | sed -e '1,/^BEGIN>>$/ d' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./matlabcmd load_file.m mydata.txt | |
./matlabcmd load_file mydata.txt # will display the output | |
./matlabcmd "randn(5)" # will display the output | |
./matlabcmd with_error.m # shows the error | |
./matlabcmd "randn(5) + randn(6)" # shows the error | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function with_error | |
a = zeros(6); | |
b = zeros(7); | |
c = a + b; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment