MATLAB Answers

How to prevent udp/fread from convertig raw byte data to double

2 ビュー (過去 30 日間)
Roland Aigner
Roland Aigner 2020 年 3 月 10 日
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 = ""
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))
...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 件)





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by