Hi,
Matlab script takes values from an udp server. Server respond contains 8 bytes so it is needed to convert this 8 bytes to an double value in matlab script.
My script:
u = udp('127.0.0.1', 49012, 'LocalPort', 85);
fopen(u);
fprintf(u,"request");
data = fread(u); % reads 8 bytes
data = typecast(str2num(sprintf('%d%d%d%d%d%d%d%d',data(1),data(2),data(3),data(4),data(5),data(6),data(7),data(8))), 'double');
disp(data)
for example its received data is as follows:
147, 190, 144, 143, 145, 126, 68, 64
It is converted to double as
1.4719e+21
but orginal value is about to 41
Note: There is no problem in server. I tested it using C# and received correct results.
Note: Reading value as double was tried like as follows:
fread(u, size, 'double')
However, this method does not make any difference.

 채택된 답변

Bruno Luong
Bruno Luong 2020년 11월 5일

0 개 추천

>> typecast(uint8([147, 190, 144, 143, 145, 126, 68, 64]),'double')
ans =
40.9888

댓글 수: 2

John Smith
John Smith 2020년 11월 5일
thank you
Yelile Iga
Yelile Iga 2022년 10월 9일
we have the same poblem, can you help us?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Write COM Applications to Work with MATLAB에 대해 자세히 알아보기

제품

질문:

2020년 11월 5일

댓글:

2022년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by