problem between arduino and matlab communication

i wanted to communicate between arduino and matlab and i have written all the codes and it is running successfully but the problem arises after 4-5 min. of serial communication between them that matlab is not able write data to arduino, it is showing error:

??? Error using ==> serial.fprintf at 144
An error occurred during writing.
Error in ==> sectioning_with_arduino at 87
fprintf(s,'%s\n','2');
what is the problem i am not able to understand?...is buffer on the port gets full and matlab is not able to write data on it again?.... please help

int led1=6,led2=7,led3=8,led4=9;
long ledcounter1=0,ledcounter2=0,ledcounter3=0,ledcounter4=0; //counters for time delay loop
long y=1900;
void setup()
{
  Serial.begin(9600);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
}
void loop()
{
            if(Serial.available()>0)
            {    
               
                 char data=Serial.read();
                 if(data=='1')
                  {
                        digitalWrite(led1,1);
                        ledcounter1=0;
                  }
                  else
                 if(data=='2')
                  {
                        digitalWrite(led2,1);
                        ledcounter2=0;
                  }
                  else
                if(data=='3')
                  {
                        digitalWrite(led3,1);
                        ledcounter3=0;
                  }
                  else
                if(data=='4')
                  {
                        digitalWrite(led4,1);
                        ledcounter4=0;
                  }
                }
              
          delayMicroseconds(4000);
          if(ledcounter1>y)
           {
                 digitalWrite(led1,0);
                 ledcounter1=0;
           }
         if(ledcounter2>y)
           {
                 digitalWrite(led2,0);
                 ledcounter2=0;
           }
         if(ledcounter3>y)
           {
                 digitalWrite(led3,0);
                 ledcounter3=0;
           }
         if(ledcounter4>y)
           {
                 digitalWrite(led4,0);
                 ledcounter4=0;
           }
         ledcounter1++;
         ledcounter2++;
         ledcounter3++;
         ledcounter4++;
         }

thank you

Did you bother reading the stickies at the top of the forum? WHERE IS YOUR CODE?