There might be some error in write() function, it would be better if you send the values using "uint8" instead of using "char"
clear;
x=6;
x=x+3;
x;
s=serialport("COM1",9600);
pause(1);
write(s,uint8(x));
- uint8 is a MATLAB function that maps an input number or array onto the range of 0 to 255 using only 8 bits of data.
- It converts the input into an unsigned 8-bit integer, where each bit in the binary representation represents a power of two.