diff --git a/mex/build/matlab/Makefile.am b/mex/build/matlab/Makefile.am
index a7bd8029bb370d990a8bb718f0ae1f9b535db2ce..c7f76ef4182591f319c670a6e4a12d9ecb7a7f14 100644
--- a/mex/build/matlab/Makefile.am
+++ b/mex/build/matlab/Makefile.am
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I ../../../m4
 
 # libdynare++ must come before gensylv, k_order_perturbation, dynare_simul_
 if DO_SOMETHING
-SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_
+SUBDIRS = mjdgges kronecker bytecode libdynare++ gensylv k_order_perturbation dynare_simul_ swz
 endif
 
 EXTRA_DIST = mex.def mexFunction-MacOSX.map
diff --git a/mex/build/matlab/configure.ac b/mex/build/matlab/configure.ac
index 6550f8e169d2c48db3b101f937016eeee867aecd..8d9577ccfb40bf5a22ab139d5d72fbb605cf19b6 100644
--- a/mex/build/matlab/configure.ac
+++ b/mex/build/matlab/configure.ac
@@ -69,7 +69,8 @@ AC_CONFIG_FILES([Makefile
                  libdynare++/Makefile
                  bytecode/Makefile
                  k_order_perturbation/Makefile
-                 dynare_simul_/Makefile])
+                 dynare_simul_/Makefile
+                 swz/Makefile])
 
 if test "x$ax_enable_matlab" = "xyes" -a "x$ax_matlab_version_ok" = "xyes" -a "x$ax_mexopts_ok" = "xyes"; then
   if test x"$ax_pthread_ok" = "xyes"; then
diff --git a/mex/build/matlab/swz/Makefile.am b/mex/build/matlab/swz/Makefile.am
new file mode 100644
index 0000000000000000000000000000000000000000..af050c60e1aa8542026d16b4727ccf93558a023f
--- /dev/null
+++ b/mex/build/matlab/swz/Makefile.am
@@ -0,0 +1,2 @@
+include ../mex.am
+include ../../swz.am
\ No newline at end of file
diff --git a/mex/build/octave/swz/Makefile.am b/mex/build/octave/swz/Makefile.am
new file mode 100644
index 0000000000000000000000000000000000000000..af050c60e1aa8542026d16b4727ccf93558a023f
--- /dev/null
+++ b/mex/build/octave/swz/Makefile.am
@@ -0,0 +1,2 @@
+include ../mex.am
+include ../../swz.am
\ No newline at end of file
diff --git a/mex/build/swz.am b/mex/build/swz.am
new file mode 100644
index 0000000000000000000000000000000000000000..51767558bfbaeb4d2c2f07899f77f5232cb75e6f
--- /dev/null
+++ b/mex/build/swz.am
@@ -0,0 +1,41 @@
+WORKING_DIR = ../../../..
+
+SWZ_SRC_DIRS = $(WORKING_DIR)/matlab/swz/c-code/utilities/TZCcode $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/matrix $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/error $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/arrays $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/ascii $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/stat $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/spherical $(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/sort $(WORKING_DIR)/matlab/swz/c-code/sbvar/switching $(WORKING_DIR)/matlab/swz/c-code/sbvar/var $(WORKING_DIR)/matlab/swz/c-code/mex
+
+vpath %.c $(SWZ_SRC_DIRS)
+
+####
+# 64
+BIT = /usr/local64
+# 32
+#BIT = /usr/local
+###
+
+###
+# TO BE REMOVED
+#MAC
+MAC_FLAG = -DMACOSX
+#GSL
+GSL_INCLUDE_DIR = -I$(BIT)/include/gsl -I/usr/local/include
+LIBS += -lgsl -lgslcblas
+#
+###
+
+DEBUG = -g
+
+CPPFLAGS += $(DEBUG) -DINTELCMATHLIBRARY $(MAC_FLAG) $(GSL_INCLUDE_DIR) -I$(WORKING_DIR)/matlab/swz/c-code/utilities/TZCcode -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/matrix -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/error -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/arrays -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/ascii -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/stat -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/spherical -I$(WORKING_DIR)/matlab/swz/c-code/utilities/DWCcode/sort -I$(WORKING_DIR)/matlab/swz/c-code/sbvar/switching -I$(WORKING_DIR)/matlab/swz/c-code/sbvar/var -I$(WORKING_DIR)/matlab/swz/c-code/mex
+
+LDFLAGS += -L$(BIT)/lib
+
+noinst_PROGRAMS = mex_sbvar_init_file mex_sbvar_estimation mex_sbvar_mhm_1 mex_sbvar_mhm_2 mex_sbvar_probabilities mex_sbvar_draws
+
+common_mex = mex_top_level.c modify_for_mex.c
+swz_common = bmatrix.c swzmatrix.c dw_error.c dw_rand.c dw_matrix_rand.c dw_array.c dw_matrix_array.c dw_matrix_sort.c dw_ascii.c dw_parse_cmd.c
+swz_tao    = tzmatlab.c mathlib.c cstz_dw.c
+
+nodist_mex_sbvar_init_file_SOURCES     = $(common_mex) $(swz_common) create_init_file.c switch.c switchio.c VARbase.c VARio.c VARio_matlab.c
+nodist_mex_sbvar_estimation_SOURCES    = $(common_mex) $(swz_common) $(swz_tao) estimate.c VARbase.c VARio.c command_line_VAR.c switch.c switchio.c switch_opt.c csminwel.c
+nodist_mex_sbvar_mhm_1_SOURCES         = $(common_mex) $(swz_common) mhm_VAR_main_1.c mhm_VAR.c VARbase.c VARio.c command_line_VAR.c switch.c switchio.c
+nodist_mex_sbvar_mhm_2_SOURCES         = $(common_mex) $(swz_common) mhm_VAR_main_2.c spherical.c VARbase.c VARio.c switch.c switchio.c mhm_VAR.c
+nodist_mex_sbvar_probabilities_SOURCES = $(common_mex) $(swz_common) probabilities.c switch.c switchio.c VARbase.c VARio.c command_line_VAR.c
+nodist_mex_sbvar_draws_SOURCES         = $(common_mex) $(swz_common) PrintDraws.c switch.c switchio.c VARbase.c VARio.c command_line_VAR.c
\ No newline at end of file