| MATLAB® | ![]() |
D = h.GetVariable('varname', 'workspace')
D = GetVariable(h, 'varname', 'workspace')
D = invoke(h, 'GetVariable', 'varname', 'workspace')HRESULT GetVariable([in] BSTR varname, [in] BSTR workspace,
[out, retval] VARIANT* pdata)
GetVariable(varname As String, workspace As String) As Object
GetVariable returns the data stored in the specified variable from the specified workspace of the server. Each syntax in the MATLAB Client section produce the same result. Note that the dot notation (h.GetVariable) is case sensitive.
varname from the specified workspace of the server that is attached to handle h. The workspace argument can be either base or global.
varname — the name of the variable whose data is returned
workspace — the workspace containing the variable can be either:
base is the base workspace of the server
global is the global workspace of the server (see global for more information about how to access variables in the global workspace).
Note GetVariable works on all MATLAB types except sparse arrays, structures, and function handles. |
You can use GetVariable in place of GetWorkspaceData, GetFullMatrix and GetCharArray to get data stored in workspace variables when you need a result returned explicitly (which might be required by some scripting languages).
This example assigns a cell array to the variable C1 in the base workspace of the server, and then read it back with GetVariable, assigning it to a new variable C2.
h = actxserver('matlab.application');
h.PutWorkspaceData('C1', 'base', {25.72, 'hello', rand(4)});
C2 = h.GetVariable('C1','base')
C2 =
[25.7200] 'hello' [4x4 double]Dim Matlab As Object
Dim Result As String
Dim C2 As Object
Matlab = CreateObject("matlab.application")
Result = Matlab.Execute("C1 = {25.72, 'hello', rand(4)};")
C2 = Matlab.GetVariable("C1", "base")
MsgBox("Second item in cell array: " & C2(0, 1))The Visual Basic Client example creates a message box displaying the second element in the cell array, which is the string hello.

GetWorkspaceData, PutWorkspaceData, GetFullMatrix, PutFullMatrix, GetCharArray, PutCharArray, Execute
![]() | gettsbetweenevents | GetWorkspaceData | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |