| MATLAB Function Reference | ![]() |
h.PutWorkspaceData('varname', 'workspace', data)
PutWorkspaceData(h, 'varname', 'workspace', data)
invoke(h, 'PutWorkspaceData', 'varname', 'workspace', data)PutWorkspaceData([in] BSTR varname, [in] BSTR workspace,
[in] VARIANT data)
PutWorkspaceData(varname As String, workspace As String,
data As Object)
PutWorkspaceData stores data in the specified workspace of the server attached to handle h, assigning to it the variable varname. The workspace argument can be either base or global.
Note PutWorkspaceData works on all MATLAB® types except sparse arrays, structure arrays, and function handles. Use the Execute method for these data types. |
MATLAB enables you to define 2-D character arrays such as the following:
chArr = ['abc';'def';'ghk']
chArr =
abc
def
ghk
size(chArr)
ans =
3 3However, PutWorkspaceData does not preserve the dimensions of character arrays when passing them to a COM server. 2-D arrays are converted to 1-by-n arrays of characters, where n equals the number of characters in the original array plus one newline character for each row in the original array. This means that chArr above is converted to a 1-by-12 array, but the newline characters make it display with three rows in the MATLAB command window. For example:
h = actxserver('matlab.application');
h.PutWorkspaceData('Foo','base',chArr);
tstArr = h.GetWorkspaceData('Foo','base')
tstArr =
abc
def
ghk
size(tstArr)
ans =
1 12You can use PutWorkspaceData in place of PutFullMatrix and PutCharArray to pass numeric and character array data respectively to the server.
Server function names, like PutWorkspaceData, are case sensitive when using the first syntax shown.
There is no difference in the operation of the three syntaxes shown above for the MATLAB client.
The GetWorkspaceData and PutWorkspaceData functions pass numeric data as a variant data type. These functions are especially useful for VBScript clients as VBScript does not support the safearray data type used by GetFullMatrix and PutFullMatrix.
Create an array in the client and assign it to variable A in the base workspace of the server:
h = actxserver('matlab.application');
for i = 0:6
data(i+1) = i * 15;
end
h.PutWorkspaceData('A', 'base', data)
This example uses the Visual Basic® MsgBox command to control flow between MATLAB and the Visual Basic Client.
Dim Matlab As Object
Dim data(6) As Double
Dim i As Integer
MatLab = CreateObject("matlab.application")
For i = 0 To 6
data(i) = i * 15
Next i
MatLab.PutWorkspaceData("A", "base", data)
MsgBox("In MATLAB, type" & vbCrLf & "A")Open the MATLAB window and type A. MATLAB displays:
A =
0 15 30 45 60 75 90Click Ok to close and terminate MATLAB.
GetWorkspaceData, PutFullMatrix, GetFullMatrix, PutCharArray, GetCharArrayExecute
See Introduction for more examples.
![]() | PutFullMatrix | pwd | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |