serial communication between matlab and arduino

i am trying to serially communicate arduino and matlab. i have to receive signals from matlab. based on the received signals arduino has to run the motors using the motor shield. the receiving led is glowing whenever the matlab sends the signal but i am unable to read those signals in the arduino. i am attaching my arduino code to read the siganls. i am also including the matlab code to transfer the signals.

tsshield.ino (1.11 KB)

Code from Original Post so others don't have to download it

#include <SD.h>

#include <Wire.h>

#include <AFMotor.h>


#include <SoftwareSerial.h>

 
 int s;
 AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm

void setup() {

  pinMode(s,INPUT);
  Serial.begin(9600);
  motor.setSpeed(200);     // set the speed to 200/255
  motor2.setSpeed(200); 
}


void loop(){

if(Serial.available()){
s=Serial.read();
  break;
  case 3:Serial.print("3"); break;
s=Serial.parseInt();
//s=Stream.read();
Serial.println();
switch(s){
  case 0: Serial.println("0");
           motor.run(FORWARD);      // turn it on going forward
  
 motor2.run(BACKWARD);      // turn it on going forward
  delay(1000);
          break;
  case 1: Serial.println("1");
      motor.run(BACKWARD);     // the other way
  
  motor2.run(FORWARD);     // the other way
  delay(1000);
  break;
  case 2:Serial.print("2"); 
        motor.run(FORWARD);      // stopped
  
  motor2.run(FORWARD);      // stopped
  delay(1000);
 
  motor.run(RELEASE);      // stopped
  
  motor2.run(RELEASE);      // stopped
  delay(1000);
  default : break;
}
}
}

...R

Have a look at the examples in Serial Input Basics for simple reliable ways to receive data. There is also a parse example.

You should also separate the code for receiving data from the code for controlling the motors so that the different parts can be tested on their own. The receiving code should store the data in variables and the motor code should do its stuff based on whatever happens to be in the variables.

...R

Hmm, your code does not compile because you have a 'case 3:' outside a switch.

Please post a fixed code so we can understand what your doing.