receivind unit8 data in array by arduino

i am trying to send unit8 data from matlab to arduino and check the values of the comming data the problem is the data is received one at a time in arduino and whenever i try to store it i fail so any help on how to store unit8data in array using arduino.

here is the matlab code

clc
delete(instrfindall);
s = serial('COM7','BaudRate',9600);
fopen(s); 
txdata = ['4';'2';'2';'2';'9'];
%Convert to decimal format
txdata_dec = hex2dec(txdata);
%Write using the UINT8 data format
fwrite(s,txdata_dec,'uint8');
y = fread(s,4, 'uint8')

here is arduino code

unsigned char buffe[5];

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

void loop() {
 if(Serial.available()) {
   for (int i=0;i<5;i++)
   {
   int s = Serial.read();
   buffe[i]=s;
   Serial.print(s,HEX);

   if(i==5)
   {
   for (int i=0;i<5;i++)
   {
      Serial.print(buffe[i],HEX);
   }
   }
 }


}
}

The buffe is a pointer to array of bytes. You should definitely use

buffe[i] = (unsigned char)s;

and also

Serial.print(buffe[i],HEX);

.

BTW: Please edit your post and use code tags for the code to be readable (left most button above edit window).

fwrite(s,txdata_dec,'uint8');

What IS the value in txtdata_dec? It looks to me like the value is 0x42229. I can’t imagine how you think that will fit in a uint8.

  if(Serial.available()) {
    for (int i=0;i<5;i++)
    {
    int s = Serial.read();

If there is one or more bytes to read, it is NOT proper to read 5 bytes.

hello Budvar10, it givees me the same result the problem is i need to check every byte received and whenever i do so it doesnot respond

if (( buffe[1] ==1 ) && ( buffe[1] ==1 ) &&   (buffe[2] ==2)&&  (buffe[2] ==2))
{
 Serial.print("abb");
}

but if i check on only one byte it works i dont know what is the problem

if (( buffe[1] ==1 ))
{
 Serial.print("abb");
}

hello PaulS,
i removed the unit_8 and the received data is 42229 and i am receiving every number as int the problem i need to store these values in an array which represent data packet and check every number in it however i cant do so when ever i check single number it works fine but when i check first and second number it doesnot work and i dont know what is wrong.

samarhefina: txdata = ['4';'2';'2';'2';'9']; }

If your data starts off as text wouldn't it be simpler all round just to send it as text.

See the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R