Execute Scilab code in strings (original) (raw)
Scilab 5.3.3
- Scilab help
- Functions
- profiling
- bytecode
- bytecodewalk
- deff
- exec
- execstr
- fun2string
- function
- functions
- genlib
- get_function_path
- getd
- head_comments
- lib
- librarieslist
- library
- libraryinfo
- listfunctions
- macro
- macrovar
- recompilefunction
- varargin
- varargout
- whereis
Please note that the recommended version of Scilab is 2026.0.1. This page might be outdated.
See the recommended documentation of this function
Scilab help >> Functions > execstr
execstr
execute Scilab code in strings
Calling Sequence
execstr(instr) ierr=execstr(instr,'errcatch' [,msg])
Arguments
instr
vector of character strings, Scilab instruction to be executed.
ierr
integer, 0 or error number.
msg
character string with values 'm' or 'n'. Default value is 'n'.
Description
Executes the Scilab instructions given in argumentinstr.
Note that instr should not make use of continuation marks (..)
If the 'errcatch' flag is not present, error handling works as usual.
If the 'errcatch' flag is set, and an error is encountered while executing the instructions defined in instr, execstr issues no error message, but aborts execution of the instr instructions (at the point where the error occurred), and resumes withierr equal to the error number. In this case the display of the error message is controlled by the msg option:
"m"
error message is displayed and recorded.
"n"
no error message is displayed, but the error message is recorded (see lasterror). This is the default.
ierr=execstr(instr,'errcatch') can handle syntactical errors. This is useful for evalution of instruction obtained by a query to the user.
Examples
execstr('a=1') execstr('1+1')
execstr(['if %t then'; ' a=1'; ' b=a+1'; 'else' ' b=0' 'end'])
execstr('a=zzzzzzz','errcatch') execstr('a=zzzzzzz','errcatch','m')
execstr('a=1?02','errcatch') lasterror(%t)
execstr('a=[1 2 3)','errcatch') lasterror(%t)
if execstr('variable1;','errcatch')<>0 then disp("Trigger an error"),end
variable2=[2,3]; if execstr('variable2;','errcatch')<>0 then disp("Trigger an error"); else disp("execstr is happy"); end
See Also
- evstr — evaluation of expressions
- lasterror — get last recorded error message
- error — error messages
- try — beginning of try block in try-catch control instruction