Serial Monitor (programming in Matlab)

Hey there

I hope some of you guys have some Matlab experience or maybe can still help me.
I want to write an Interface for Matlab that works just like the Serial Monitor in Arduino.
But unfortunately, I do not have much experience with electronics, so I hope my questions do not sound too stupid. ^^’

So it is an Arduino Diecimila Board board I am using and there are six pins on it which I should make visible in Matlab. They are the Analog Input pins.

So I have a little function, with which I can get some output for one port.
But as I said, I understand some programming but little electronics and not much about ports. So I don’t really know, how to open the additional ports and what port corresponds to what pin on the board (which is my biggest question, e.g. to which pin does “COM3” correspond?).

Does anybody know, what I have to enter, in order to get numbers like in the Serial Monitor for those six analog inputs?

The Matlab code looks like this:

function serialMonitor

clear all;
close all;
s = serial('COM3'); %assigns the object s to serial port
set(s, 'InputBufferSize', 256); %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]);
fopen(s);           %opens the serial port
while(t <= 200)  %Runs for 200 cycles - if you cant see the symbol, it is "less than" sign. so while (t less than 200)
   a =fread(s); %reads the data from the serial port and stores it to the matrix a
   a=max(a);  % in this particular example, I'm plotting the maximum value of the 256B input buffer
   x =[x a];  % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
                 %Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
                  %data at the end!
   axis auto;
   grid on;
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   a=0;  %Clear the buffer
fclose(s); %close the serial port


I want to write an Interface for Matlab that works just like the Serial Monitor in Arduino.

The Arduino doesn't know, or care, what is on the other end of the serial port. So, whatever code was writing to the serial port that the Serial Monitor application was reading will continue to write to the serial port that matlab is reading from.

It is pretty easy interfacing with matlab via the serial, i have tinker with it and its great but remember that matlab isnt that fast so if you send data to fast your matlab wont keep up with the streaming and you will see a delay in the data.
the serial interface is basically 2 pins, Rx and Tx ( receive and transmit) with which you send data using bits. all you need to set is the bound rate on both sides and the format of the transmitting data. the arduino will send the data via the serial each time you perform serial.print
i add the files i have used.

arduino_data_aquire.m (533 Bytes)

AnalogReadSerial.ino (680 Bytes)