MATLAB: Serial communication, (read, write from/to arduino ) on MATLAB Support Package for Arduino® Hardware

arduinoMATLABserial

Hello there,
I'm trying for over a week now to find the proper way to read and write from/to arduino via Matlab. I am using the MATLAB Support Package for Arduino® Hardware, (the new one not legacy). If I am not mistaken in the legacy package the code for reading what was printed in the arduino IDE serial monitor was something like
s = serial (COM3)
fopen (s)
out = fscanf(s)
Is there a way to do the same thing with the new package and how?

Best Answer

Thank you for you quick reply. By "new" and "legacy" packages I mean this
"http://www.mathworks.com/hardware-support/arduino-matlab.html"
and this
"http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino"
respectively.
Now, from what I understand, if i create an arduino object using
a = arduino ('COM3')
I can manipulate the pins, therefore the circuit, and it would be like matlab runs the "main" and arduino is just peripheral (an extention).
On the other hand if I create a serial object using
a = serial ('COM3')
fopen(s)
etc...
I would be able to read whatever the arduino print in its Serial Monitor but I won't be able to manipulate the i/o pins directly (I could to sent a command through the serial and then have the arduino do something when it receives that command). In this case I believe that the arduino is runing its code and matlab just observes.
I tried to implement both arduino and serial objects but I get an error saying that "COM 3 is in use by another object"
So, my questions are. 1) Am I right in my assumptions or have I misunderstood something 2) If I am right is there a way to observe the serial monitor by creating an arduino object
I would prefer to use Matlab code instead of simulink model.
Thank you in advance
Related Question