Serial Communication With Matlab Using Timer Functions

I'm trying to setup serial communication between Matlab and an Arduino. As a test I have a logical input to the Arduino (it can be either 0 or 1). I then want to pass the value of the input to Matlab and display it. Here's the Arduino code I have:

void setup() {
  pinMode(5, INPUT);

void loop() {
  int NPleft = digitalRead(5);

Here's the Matlab code:

clear all
s1 = serial('COM3');    % define serial port
s1.BaudRate=9600;               % define baud rate

I want Matlab to check the value being sent to it serially every second. What ends up happening is it just displays the first value it gets over and over again. So if the first value of the input is 1, it keeps displaying 1 over and over again regardless if the input goes back to 0. What am I doing wrong?

How big is the serial buffer on the Matlab side? Your Arduino code is streaming millions of bytes per second to the serial port. Add a delay(1000) after the Serial.print(), to send data just once per second.