You are on page 1of 2

MATLAB to GAUSS Translator

Written by Hang Qian


Iowa State University

Introduction

Welcome to the MATLAB to GAUSS Translator, a program that help you convert your MATLAB codes into
GAUSS codes. MATLAB and GAUSS have many similarities in grammar, which permit a literal translation
from one to the other. Analogous to translation between two human languages, the program cannot
generate perfect GAUSS codes. A natural question is: what is the accuracy rate? Surprisingly, conditional on
correct original MATLAB codes, the quality of translation is negatively correlated with the quality of your
MATLAB codes. Imagine the complexity of translating a famous English poem into Spanish, we will recognize
the challenge of translating beautiful Matlab codes with clever matrix manipulation into GAUSS language. A
wild guess of the conversion accuracy for most MATLAB codes is about 80%. It inevitably leaves some errors
and omissions for the user.

Usage
First, make sure your MATLAB file is free of grammatical error. At least all brackets are balanced.
Next, copy and paste your MATLAB file into the current folder.
Then there are a number of ways to proceed.
1) Type setup in the MATLAB command window, and enter your file name in the graphic interface.
2) Double click setup.m and press F5, and enter your file name in the graphic interface.
3) Call MAT2GAS() function with your file name as the input argument.
Then the MATLAB to GAUSS Translator will translate the codes and generate a new file with the same name
except for the extension .gas

Limitations

It is just a derivative of my MATLAB to R translator and the capability of GAUSS translation is weak. In the
future, the program can be improved when the author has more spare time and resources.

Extension
You can enhance the power of the MATLAB to GAUSS Translator by adding new rules. New rules can be
mostly easily added in EXTENSION0.m, EXTENSION1.m and EXTENSION2.m.
EXTENSION0.m allows you to translate a MATLAB expression into GAUSS expression. Essentially, it is just a

find and replace. For example you can replace eps in MATLAB with .Machine$double.eps in R.
whole word find and replace.
EXTENSION1.m allows you to translate a single-output MATLAB function into GAUSS expressions (not
necessarily functions). First, you provide a MATLAB function name, and be sure to add a left bracket, say
reshape(. Since the order of input arguments of reshape is well-defined in MATLAB, you do not need to
provide more information. Second, you write the translated GAUSS codes. For example, the counterpart of
length(A) in GAUSS is rows(A) or cols(A). So you vectorize it and write cols(vec(arg{1})), where arg{1}, arg{2},
arg{3} stands for ordered arguments in the MATLAB function. Note that the translated GAUSS codes are not
necessarily an GAUSS function. It can be some GAUSS scripts, but arg{1}, arg{2}, arg{3} should appear in it.
Essentially, what the program does is to replace arg{1}, arg{2}, arg{3} with the arguments appears in
user-supplied MATLAB codes.
EXTENSION2.m allows you to translate a double-output MATLAB function into GAUSS expressions. For
example, [V,D] = sort(A) can be translated as V=sort(A); D=sortindc(A). So you provide the MATLAB function
name sort(, and the translated codes sort(arg{1}) and sortindc(arg{1}).
You can test the effects of your list by directly calling EXTENSION0.m, EXTENSION1 or EXTENSION2 without

invoking the MATLAB to GAUSS Translator main program.

Conclusion
Machine translation between MATLAB and GAUSS is similar to the translation of language between two
counties. Literal translation may yield unexpected results. This reminds me of a story. When I studied
English in the middle school, I was taught how to translate the word lettuce to my mother tone. I thought it
is a vegetable similar to gait broccoli stalks/stems without crowns. I felt puzzled how it could be an
ingredient of salads. Not until I came here and shopped a grocery store did I realize the meaning of lettuce
completely different from my previous belief. In the same vein, do not blindly trust the GAUSS codes
generated by the MATLAB to GAUSS Translator.

Contact information
Written by Hang Qian, Iowa State University
Contact me: matlabist@gmail.com
More econometrics routines and pedagogical economics software are available at
http://www.public.iastate.edu/~hqi/

You might also like