encoding - How to make MATLAB return char instead of ASCII? -
so, i'm using @ commands matlab return caller id, doesn't matter.
everything working great except fact returns ascii numbers , have take time "translating" ascii code char can know saying.
>> s = serial('com8'); >> fopen(s) >> fwrite(s, [65 84 43 67 82 67 61 49 13]) >> s serial port object : serial-com8 communication settings port: com8 baudrate: 9600 terminator: 'lf' communication state status: open recordstatus: off read/write state transferstatus: idle bytesavailable: 47 valuesreceived: 0 valuessent: 18 >> fread(s, 47)
it returns me 47 ascii numbers this(note have deleted of returned code):
ans = 65 84 43 67 82 67 61 49 13
i've tried following things:
char(fread(s,47))
and
z = fread(s,47) char(z)
but neither of worked,
z = [65 84 43 67 82 67 61 49 13] char(z)
works fine. suppose because fread
returns ascii code newline between them , not space wrote in code above.
try str2double
, str2num
or subtract '0'
( ascii value of char '0' ) ascii code have.
Comments
Post a Comment