arduino - matlab gui- serial communication

i have been working on this project many days but i did not succeed, please help.
i want to send from the matlab gui 3 variables (each long byte) and receive them in arduino.
i found this code, but it did not work, any clue where is the problem?

matlab part: (i opened gui - insert a edit text and placed this code)

function stepInput_Callback(hObject, eventdata, handles)

xyz = get(hObject,'String');

disp('Value entered: ')

disp(xyz)

global COM;

global s;

s = serial(COM,'BaudRate',9600);

fopen(s);

disp('After OPEN')

disp(s)

fprintf(s,xyz);

fclose(s);

disp('After CLOSE')

disp(s)

arduino part:

int x;

int y;

int z;

void setup() {
pinMode(2,OUTPUT);
pinMode(6,OUTPUT);
pinMode(10,OUTPUT);
Serial.begin(9600);
}

void loop() {
if (Serial.available()) // check if Serial data is available to read
{
x = Serial.parseInt();
y = Serial.parseInt();
z = Serial.parseInt();
if (Serial.read() == '\n') // check if ENTER has been pressed (newline)
{
digitalWrite(2,1);
delay(x);
digitalWrite(6,1);
delay(y);
digitalWrite(10,1);
delay(z);
digitalWrite(10,0);
delay(z);
digitalWrite(6,0);
delay(y);
digitalWrite(2,0);
delay(x);
}
}
}

Every time you open the serial port, you reset the Arduino. Every time you close the serial port, you reset the Arduino. So, stop doing that!

Thank you PaulS
do you mean that in arduino code, i should close the "}" after :

z = Serial.parseInt();

and not at the end?
i tried it and changed :

if (Serial.read() =='\n')

to

if (Serial.read() <='\n')

now the leds are turning ON whenever i press the "enter" key regardless of the values

where am i mistaken ?

do you mean that in arduino code, i should close the "}" after :

No. There is nothing wrong with your Arduino code.

where am i mistaken ?

You are trying to fix the wrong end. The problem isn't on the Arduino end. You are not opening and closing the serial port on the Arduino end.

so it is a matlab code error :S
please how can i fix it ?

please how can i fix it ?

I've already answered that. You need to open the serial port ONCE. Then, wait for the Arduino to reset. Then, run the whole rest of the matlab application. When done, close the serial port.