Documentation:Tutorial:APIs:MATLAB - MdsWiki
Navigation
Personal tools

From MdsWiki

Jump to: navigation, search

Reading and writing data in MDSplus trees in Matlab

Observe first that the matlab interface is not directly created by the make procedure of MDSplus. The following steps for the installation are required within Matlab:

  • Include the path of the MDSplus-Matlab interface directory in the search path list of Matlab. In Matlab 6 and following, this requires selecting option File->Set Path... and then adding the directory containing the MDSplus interfaces files in the Set Path form. On windows such directory is usually \Program Files\mdsplus\matlab, while on Unix is usually /usr/local/mdsplus/matlab;
  • Make sure that environment variable MDSPLUS_DIR is defined as the root directory of the MDSplus distribution (e.g. /usr/local/mdsplus);

The following commands read the Y and X axis of node :SIGNAL1 into Matlab variables y and x.

>> mdsopen('my_tree', -1)
>> [y,status] = mdsvalue(':SIGNAL1')
>> [x,status] = mdsvalue('DIM_OF(:SIGNAL1)')

Note that the function returns both the result of the evaluation of the passed TDI expression and an integer variable containing the status for the operation (assumed to be successful if odd).

In the following example an array is written into node :NUM1

>> a=sin((0:100)/10.)
>> mdsput(':NUM2', '$1', a)

And finally, let's write a sinusoidal waveform in :SIGNAL1

>> x = (0:1000)/50.
>> y = sin(x)
>> mdsput(':signal1','BUILD_SIGNAL($1,,$2)',y,x)


Setting up access via java mdsobjects.jar

By default the Matlab API is bridging thru mdsobjects.jar. For this you need to add the jar to your javaclasspath.txt. Further you have to add the folder of the libraries to javalibrarypath.txt. This script may help you doing that

addpath(fullfile(getenv('MDSPLUS_DIR'),'matlab'));
savepath;

%system(sprintf('echo %s> %s',[regexprep(getenv('MDSPLUS_DIR'),'\\','/'), '/bin64'],fullfile(prefdir,'librarypath.txt')));%old versions
system(sprintf('echo %s> %s',fullfile(getenv('MDSPLUS_DIR'),'bin64'),fullfile(prefdir,'javalibrarypath.txt')));%new versions
system(sprintf('echo %s> %s',fullfile(getenv('MDSPLUS_DIR'),'java','classes','mdsobjects.jar'),fullfile(prefdir,'javaclasspath.txt')));


Setting up access via pyhton API

To activate the pyhton API make sure the python MDSplus package can be found in your PYTHONPATH. Then once e.g. in startup.m execute "mdsUsePython(1)".