Sending values from Matlab to arduino using serial communication I want to send numeric value from matlab to arduino but code is not working. 

Matlab code is as:

doi = 3 ;
arduino=serial('COM5','BaudRate',9600); % create serial communication object 
fopen(arduino); % initiate arduino communication
fprintf(arduino, '%s', char(doi)); % send answer variable content to arduino
fclose(arduino); 


Arduino code is as:

  int solenoidPin = 13; //This is the output pin on the Arduino
int doi;

void setup()
{
  Serial.begin(9600);
  //pinMode(13, OUTPUT);
  pinMode(solenoidPin, OUTPUT); //Sets that pin as an output
}
void loop()
{

  if(Serial.available()&gt;0)
  {

    doi = Serial.read();
    //Serial.println(doi);
    //Serial.println("\n");
    //doi = doi - 48;
   if (doi == 1)
   {
    //Serial.println(1);
    digitalWrite(solenoidPin, HIGH); //Switch Solenoid ON
    delay(1000); //Wait .15 Second
     digitalWrite(solenoidPin, LOW);
    }
  else if (doi == 2)
    {
     //Serial.println(2);
    digitalWrite(solenoidPin, HIGH); //Switch Solenoid OFF
    delay(2000); //Wait .165 Second
    digitalWrite(solenoidPin, LOW);
    }
  else 
    {
      //Serial.println(3);
      digitalWrite(solenoidPin, HIGH); //Switch Solenoid OFF
      delay(3000); //Wait .180 Second
      digitalWrite(solenoidPin, LOW);
    }

  }
}


I used str2num(doi) also instead of fprintf(arduino, '%s', char(doi)) but no output. 

Please give suggestion to correct this.

Thanks.
You send a string of ASCII characters representing a number in human readable format.

You then read one of those characters that represents a single digit and then try and use it as if it were a number.

Instead you need to read the whole string of numbers (which means having some way of knowing where the end of the numbers are in the stream of characters that arrive) and then interpret it back into a number again.