Sending Integer From MATLAB to Arduino

No matter what i did, i couldn't be able send the data from matlab to arduino.
Can anyone please tell me what i am doing wrong?

int ibyte;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available()>0)
  {
    ibyte=Serial.read();
    Serial.println(ibyte);
  }
}
clc
clear all
s = serial('COM13');
set(s,'BaudRate', 9600);
set(s,'DataBits', 8);
set(s,'StopBits', 1);
fopen(s);
s.ReadAsyncMode = 'continuous';
fwrite(s,3);
out = fgetl(s)
fclose(s)
delete(s)
clear s

3 is the integer that i want to send and get back bu it did not work. the matlab code is working when arduino sends some codes like

Serial.println("hello");

i can get "hello" from matlab but matlab couldn't be able to send commands to arduino.

int ibyte;

I really hate to see a type used in the name of a variable. This is especially true when the type in the name does not match the type of the variable.

When you call Serial.read() only inside an if(Serial.available() > 0) block, the data from the Serial.read() method will all be in the low order byte, so the type of the variable that the data is stored in can be byte.

Aside from that, you send 3. Are you sending the value 3 as a byte, the value 3 as an int, or the value “3” as a string? It pays to KNOW.

Does the RX LED on the Arduino blink?

What do you get back?

By the way, you know that opening the serial port resets the Arduino, right? You then send data to the Arduino before it has finished booting. That doesn’t seem like a good idea.