How to convert four bytes into double ?
조회 수: 26 (최근 30일)
이전 댓글 표시
Hai, my requirement is mentioned below;
i m using Ethernet TCP IP communication and handshake was done sucessfully.
Then am using animated line plot with "addpoints" command. In addpoints command -> it supports only "double" data type for X & Y Axis, but my input value for Y axis is four bytes / two bytes.
How to convert two or four byte into double ? any byte swap need to be done ? if yes means pls comment your suggestion !!
here i will add my Matlap code:
a = tcpclient('192.168.10.4',2000,'Timeout',10,'ConnectTimeout',30); %Establish Communication
Data = read(a,8,"uint8"); %Read Values from Server
figure
h = animatedline;
ax = gca; % Current Axes
ax.YGrid = 'on';
ax.YLim = [0 500];
stop = false;
startTime = datetime('now');
while ~stop
Data = read(a,8,"uint8"); %%%% i need to convert double
t = datetime('now') - startTime;
xx = datenum(t);
addpoints(h,xx,Data);
댓글 수: 0
채택된 답변
Walter Roberson
2022년 10월 14일
편집: Walter Roberson
2022년 10월 14일
댓글 수: 5
Walter Roberson
2022년 10월 15일
Could you give an example of the sequence of 4 bytes, and the corresponding numeric value that you expect?
Also I am still concerned about how sometimes you do not have exactly 4 bytes ? Please explain that further.
추가 답변 (1개)
Noah Prisament
2023년 7월 19일
편집: Noah Prisament
2023년 7월 19일
The "animatedline" now supports all numeric datatypes along with datetimes and durations natively as of R2023a!
In order to plot your data on an "animatedline" you can now utilize the following syntax:
h = animatedline(NaT-NaT, uint8(NaN));
addpoints(h,xx,Data);
You also don't have to convert the duration to a datenum anymore either. Use NaT-NaT for for a duration and NaT for datetimes.
댓글 수: 2
Walter Roberson
2023년 7월 19일
I suspect you intended
h = animatedline(NaT-NaT, uint8(NaN));
Noah Prisament
2023년 7월 19일
편집: Noah Prisament
2023년 7월 19일
I did, thank you for catching the typo! I am editing the original answer so that it isn't copied incorrectly.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!