Problems using COM port with MatLab to comunicate with Arduino

¡Hi friends!

It is the first time I try to comunicate Arduino with Matlab. I’ve read that there is a hardware support for arduino devices, but I want to comunicate them via a COM port.
My final objetive is to create a serial monitor (in order to analize and operate with the data MatLab receives from arduino), very similar to the Arduino’s serial monitor. The first step I tried is only to send bytes every second from Arduino and receive it with matlab to print it, but I did not succes.
I am using MatLab 2014a and an Arduino UNO (The SMD ONE :3)
The code I uploaded to my Arduino creates a byte variable with 20 as initial value, then it sends it to via serial port, increment it, sends it again, and so on. Here is the code:

void setup() {

void loop() {
  static byte B = 20;

In the other hand, in Matlab I am using this: (The thing I tried to do is that MatLab displays the bytes Arduino sends, just as the Arduino’s serial monitos does):

%Creates and configure a serial object and opens the port
P = serial ( comPort );
set( P , 'DataBits' , 8 );
set( P , 'StopBits' , 1);
set( P , 'BaudRate' , 9600);
set( P, 'Parity' , 'none');
%Read the byte and display it 

I expected to receive a number instantly, but after I enter the comand MatLab pauses by a short time and then displays some numbers (instead of just one) and sends a warning 'Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period." (I atacht a picture so as to you understand the problem)

I would be very grateful for your help, I am sure that it is not as simple as writing ‘fread( “serial object” )’, but I don’t know the correct way to do it, particularly to say to MarLab when stops reading.

Previous matlab discussions:

I imagine it would be difficult to emulate the Arduino Serial Monitor in MATLAB, as it uses a file-oriented IO system rather than character-oriented. You might look around to see if anyone has written a MATLAB program to emulate a com port terminal program, and start with that. However, I did a little searching and did not find an example.

I suggest to just use the standard MATLAB - Arduino interface to collect data, and go from there.

after I enter the comand MatLab pauses by a short time and then displays some numbers (instead of just one) and sends a warning

I don't know Matlab but what you describe sounds like your Matlab program is not properly designed to allow for the Arduino resetting when Matlab opens the serial port.