Problem interfacing: Matlab to Arduino

Hello guys, I need some advice. I need send data from matlab to arduino and back. I only need send 5 numbers. Which in the future will be: 0 - continue; 1 - turn left; 2 - turn right; 3 - rotate 180 degrees; 4 - stop. I need to verify that these 5 numbers came to Arduino and back to matlab. I use Arduino Uno. Below is my code which i used for Matlab and Arduino. When a try send data matlab show me this Warning: Unsuccessful read: A timeout occurred before the Terminator was reached. Sorry for my English. Thank You for your help.

Matlab code:

clear all

answer = [0,1,2,3,4];
arduino=serial('COM7','BaudRate',9600); % create serial communication object on port COM7

%Change the Terminator property of the serial port to make it faster

fopen(arduino); % initiate arduino communication

fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino

out = fscanf(arduino);
out = double(out);

fclose(arduino); % end communication with arduino


Arduino code:

char i;
void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

I don't know Matlab but your code seems to open the serial port, do stuff and then close it. That does not work with an Arduino because the Arduino resets when the serial port is opened and Matlab must allow time for the reset process. Also it should open the port and keep it open.

Look at how this is managed in this Python-Arduino demo.

The simple reliable examples in serial input basics may be useful for the Arduino code.