Communicate between Max/MSP and MATLAB


    deepdrumms's icon
    deepdrumms's icon
    Mar 09 2010 | 6:03 am
    I'm looking to have Max serve as the front-end GUI for calling a few MATLAB scripts I've written. I've been searching around the internet for a few days now and have yet to find a working solution for communicating between the two programs. I did try using CNMAT's "matlabcommunicate" object, but it seems to be broken or incompatible. Does anyone know of way to transfer data between the two? All I need to do is either send data from a buffer~ to a MATLAB array, or vice versa. The CNMAT object apparently does this, but I cannot get it to work (the object doesn't load correctly).
    Here's a link to the files:
    And here's the error I get: matlabcommunicate: unable to load object bundle executable 2010-03-08 19:29:06.404 MaxMSP Runtime[757:207] Error loading /Applications/Max5/Cycling '74/max-externals/matlabcommunicate.mxo/Contents/MacOS/matlabcommunicate: dlopen(/Applications/Max5/Cycling '74/max-externals/matlabcommunicate.mxo/Contents/MacOS/ma tlabcommunicate, 262): no suitable image found. Did find: /Applications/Max5/Cycling '74/max-externals/matlabcommunicate.mxo/Contents/MacOS/matlabcommunicate: mach-o, but wrong architecture

    • 7391's icon
      7391's icon
      Mar 09 2010 | 8:18 am
      did you read the How-to-use-it text ? Here it is
      Go to a bash shell and set the shell variables MATLAB, DVLD_LIBRARY_PATH, and PATH, then start Max from this terminal.
      You should be able to cut and paste this text into a Terminal window:
      bash # Note this kludge to get /Applications/MATLAB701, /Applications/MATLAB704, etc: MATLAB=echo /Applications/MATLAB* export MATLAB DYLD_LIBRARY_PATH=$MATLAB/bin/mac:$MATLAB/sys/os/mac:$DYLD_LIBRARY_PATH export DYLD_LIBRARY_PATH PATH=$MATLAB/bin:$PATH export PATH open /Applications/MaxMSP 4.5/MaxMSP
      For Remote:
      Start the X server on your machine xhost +[ip_address_of_matlab_server] Make sure your path on the matlab server includes the Matlab directory
      Type this in a terminal on my laptop to run Matlab on the G5: ssh ls ssh "/bin/csh -c 'setenv DISPLAY; printenv'" ssh "/bin/csh -c 'setenv DISPLAY; /usr/X11R6/bin/xclock'" ssh "/bin/csh -c 'matlab -nojvm'" ssh "/bin/csh -c 'setenv DISPLAY; matlab'"
    • ch's icon
      ch's icon
      Mar 09 2010 | 8:23 am
      CNMAT does not distribute an intel or ub version at the moment. that's why you got :
      /Applications/Max5/Cycling '74/max-externals/matlabcommunicate.mxo/Contents/MacOS/matlabcommunicate: mach-o, but wrong architecture
    • deepdrumms's icon
      deepdrumms's icon
      Mar 09 2010 | 5:08 pm
      So assuming I won't be able to use matlabcommunicate, are there any other ways of doing this? How about creating a Max external in C that calls the matlab engine?
    • deepdrumms's icon
      deepdrumms's icon
      Mar 10 2010 | 7:37 am
      Just to complete this topic, I did find a working solution. Andy Schmeder at CNMAT wrote some MATLAB code for sending and received OSC messages over UDP. In combination with udpsend/receive in Max, I was able to send numbers, strings, and lists between the programs. Straight forward and very easy to use.
      Here's the link if anyone else is interested:
      Thanks again
    • OBNOXIUs's icon
      OBNOXIUs's icon
      Mar 20 2010 | 5:04 pm
      Would it be possible to give a bit more information about your solution?
      For my bachelor project I need both Max/MSP and MATLAB, and the plan was to send the data (numbers) from Max to MATLAB via osc/udp.
      I had already discovered the Matlab OSC toolbox, but I can not get it to work...When I try the example .m files (like osc_pingpong_a.m), it just times out without receiving anything. Maybe I should contact Andy Schmeder himself about this, but probably I'm just doing it wrong.
      deepdrumms, could you give an example of an .m file that can receive data sent with 'udpsend' in Max?
      ps. I'm very (very!) new to Max/MSP, with MATLAB I'm a bit more familiar :)
    • Clayton Mosher's icon
      Clayton Mosher's icon
      Clayton Mosher
      May 27 2016 | 4:13 am
      I see that this thread is six years old... but finger's crossed, can someone help? I'd like to send data directly to Max from MatLab. The link to Andy Shmeder's site no longer seems active -- can you help deepdrumms? I'm working on a PC and have tried applying the bash code (but I think my directories are wrong... can you help me understand what each of these directories mean and how I can customize it to my computer:
      Any tidbit of direction would be super helpful... I'm stuck.