diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m
index d70c2c2fdb57ad4baedf04e8d877df63109f7027..149d2f9edaf8e8b097c43f58544e4492b4a7e3ea 100644
--- a/matlab/dynare_solve.m
+++ b/matlab/dynare_solve.m
@@ -40,13 +40,19 @@ jacobian_flag = options.jacobian_flag;
 
 % Set tolerance parameter depending the the caller function.
 stack = dbstack;
-if strcmp(stack(2).file,'simulation_core.m') || strcmp(stack(2).file,'solve_stacked_problem.m')
+if isoctave
+    [pathstr,name,ext]=fileparts(stack(2).file);
+    caller_file_name=[name,ext];
+else
+    caller_file_name=stack(2).file;
+end
+if strcmp(caller_file_name,'simulation_core.m') || strcmp(caller_file_name,'solve_stacked_problem.m')
     tolf = options.dynatol.f;
 else
     tolf = options.solve_tolf;
 end
 
-if strcmp(stack(2).file,'dyn_ramsey_static.m')
+if strcmp(caller_file_name,'dyn_ramsey_static.m')
     maxit = options.ramsey.maxit;
 else
     maxit = options.steady.maxit;