Reading Value from Teensy 3.5 to Matlab

Hey all, I'm working with a TeensyDuino 3.5, and I'm trying to read a continously updated byte via Serial to Matlab. This signal is simply a flag that I want to be high under some conditions, and low every other time. I've simplified my code down to just the transmission and reception of Serial data, and I can't figure out what Matlab function I should be using, or what type of transmission I should do in Arduino.

My Arduino Code:

byte val = 0;
unsigned long past;

void setup() {
Serial.begin(9600); //Teensy ignores parameter and runs at 12MB/sec
past = millis();

void loop() {

unsigned long currTime = millis();
if ((currTime - past) > 5000){
// Every 5 seconds change the value of the transmission
past = millis();
val = 1-val;

My Matlab Code:

% Serial Read debug

coms = instrfind;

if ~isempty(coms)

SerialID = serial('COM13', 'BaudRate', 9600);

test = fread(SerialID, 512);


test_new = fread(SerialID, 512);


test_old = fread(SerialID, 512);


test_new_new = fread(SerialID, 512);


Each fread returns the same array. How can I fix this?

Matlab probably works like other programming languages, you would need to open serial port and read one byte at a time.