How to prevent udp/fread from convertig raw byte data to double
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to read encoded raw data from UDP and to pass it to my custom MEX file for decoding. Now what I get when I use fread to read data from my UDP port are doubles. Also, the documentation for udp/fread tells that
"By default, numeric values are returned in double precision arrays"
however, what it doesn't tell is how I can prevent this conversion and how to get the raw byte values instead. I have no use of floating values and would have to convert back in my MEX file, which would cause unnecessary overhead.
So, if I do something like this:
u = udp();
u.LocalPort = 3333;
fopen( u );
data = fread( u, 10, 'uint8' );
fclose( u );
... and send for example via this little Python script:
import time
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 3333
MESSAGE = "Hello, World!"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
time.sleep(.100)
...then, just as the documentation of udp/fread tells, the Matlab code treats input as uint8 and returns doubles. However, in contrast to the fread documentation for reading from files, the UDP version seems to have no understanding of * or => syntax to specify output types.
How can I prevent this conversion from uint8 to double?
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!