PutWorkspaceData - Store data in server workspace

Synopsis

MATLAB® Client

h.PutWorkspaceData('varname', 'workspace', data)
PutWorkspaceData(h, 'varname', 'workspace', data)
invoke(h, 'PutWorkspaceData', 'varname', 'workspace', data)

Method Signature

PutWorkspaceData([in] BSTR varname, [in] BSTR workspace, 
[in] VARIANT data)

Microsoft® Visual Basic® Client

PutWorkspaceData(varname As String, workspace As String, 
data As Object)

Description

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.

Passing Character Arrays

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     3

However, 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    12

Remarks

You 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.

Examples

Create an array in the client and assign it to variable A in the base workspace of the server:

MATLAB® Client

h = actxserver('matlab.application');
for i = 0:6
   data(i+1)  = i * 15;
end
h.PutWorkspaceData('A', 'base', data)

Visual Basic® .NET Client

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    90

Click Ok to close and terminate MATLAB.

See Also

GetWorkspaceData, PutFullMatrix, GetFullMatrix, PutCharArray, GetCharArrayExecute

See Introduction for more examples.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS