Some issues using with Matlab


I am communicating between Matlab and my Arduino, but only one of my commands is reading what I'm expecting. The commands that are not reading what I expect are instead reading 10 (from what I understand this is a translation of an ASCII line feed to a DEC integer) source: Arduino Reference - Arduino Reference). I have run some tests and can confirm that feeding an 'a' to Arduino makes it read 97 with from Matlab.

Here is a snippet of my Arduino code:

void setup() {
pinMode(test_Out, OUTPUT);
pinMode(serial_Search_Pin, OUTPUT);
char a = 'b';
while (a != 'a')
a =;

void loop()

if (Serial.available() > 0)
mode =;
digitalWrite(test_Out, HIGH);
switch (mode)

//Cases 1-5 are here in the actual code, I have omitted them for simplicity

case 6:
while (Serial.available() == 0){
} //An effective method to wait until there is an available character, I have ran the code without this while loop and the returns -1 for no data.
storage =;

I have confirmed that the Arduino is successfully reading in the 6 and switching to the proper case by changing the Serial.println(storage) to Serial.println(mode), and the 6 is being returned to Matlab. The 6 is originally passed to the Arduino through Matlab with: fprintf(out.s,6)

The strange thing is that when I reach the inside case 6, the Arduino reads a 10 even though my Matlab code uses: fprintf(out.s,30), NOTE: This 30 is arbitrary, I have tried many variables and every single one returns 10. Does anyone have any idea of what is going on here? I have been successful at switching between cases 1-6 at a rapid rate (full cycle at least 10Hz), but the inside of the cases always returns a 10, even though the fprintf and fscanf in Matlab are handled in the exact same way. When the code loops back to the original, it once again successfully reads the case number from Matlab and properly switches.

I have checked that all of my variables are properly declared and omitted it for simplicity, if someone would like the full code I can provide it. I can provide the Matlab code as well if necessary, thanks!