(translator=pacific, ChineseSource=pacific-20020530-8\evalin.html, EnglishSource=c:\matlabr12\help\techdoc\ref\evalin.html)
MATLAB Function Reference    
evalin

在工作欄(workspace)中執行含有MATLAB指令的字串。

Syntax

Description

evalin(ws,expression) 在工作欄 ws(in the context of the workspace ws)中執行含有合法MATLAB指令的字串 expressionws 可以為 'base' 或 'caller' 來指定基本工作欄( base workspace) 或 呼叫者函式的工作欄(the workspace of the caller function)。 你也可以用中括號(square brackets)把子字串組合成 expression

[a1,a2,a3,...] = evalin(ws,expression) 執行 expression 並回傳指定輸出值的結果。我們建議使用 evalin 輸出引數而不建議將輸出引數放進 expression 字串中:

上列指令中,MATLAB解析器(parser)並不會嚴格檢查 expression,所以可能產生錯誤和其他難以預料的情況。

evalin(ws,expression,catch_expr) 執行 expression 。若發生錯誤時,則執行 catch_expr。 而 lasterr 函式可在 expression 發生錯誤時接收到錯誤訊息。當 expression 是從子字串組合而成時,這將會十分有用。若不是因為組合子字串產生的錯誤,可用 try...catch 來控制程式碼的流程來檢查。

Remarks

 MATLAB的基本工作欄(base workspace)可以在命令列(command line)中看到 (當不在偵錯模式時)。 而呼叫者工作欄( caller workspace)是被稱為M檔案的函式的工作欄。 要注意的是,基本工作欄和呼叫者工作欄在被MATLAB命令列所呼叫的M檔案內文中是一樣的。(Note, the base and caller workspaces are equivalent in the context of an M-file that is invoked from the MATLAB command line.)

Examples

下列範例抓取在MATLAB基本工作欄(base workspace)中的變數 var 並擷取區域變數 v

Limitation

evalin 不能做遞廻式的運算。舉例來說,無法執行下列指令:

evalin('caller','evalin(''caller'',''x'')')

See Also

assignin, catch, eval, feval, lasterr, try


 evalc exist