getting data from an array correctly
이전 댓글 표시
Hi, I have the following data that I get it from the socket
header = [53 0 1 2 3 4 5 6 7 8 9 53 1 24 59 5 95 95 53 2 59 58 575 75 53 0 1 4 2 4 9 1];
The header first starts with 53, then maybe 0 or 1 or 2. so I need to get the bytes after 53 + 0 till the next 53 ( in between) and also get the data after 53 + 1 till the next 53 and so on
I tried that but it crashes
header = [53 0 1 2 3 4 5 6 7 8 9 53 1 24 59 5 95 95 53 2 59 58 575 75 53 0];
where = find(header == 53);
if numel(where) > 1 && header(where(1)+1) == 1 % check if there are more then 1 53s and number after first 53 is 0.
nextbytes = header(where(1)+2:where(2)-1);
disp(nextbytes);
end
댓글 수: 4
Walter Roberson
2018년 5월 24일
If the data itself included a 53, then how would that be coded?
What do you want to do in the case of a 53 followed by something that is not a 0, 1, or 2 ?
Ahmed Tolba
2018년 5월 24일
dpb
2018년 5월 24일
Is it possibly data, though, even if not new record marker?
A formal description of the protocol would be more beneficial, methinks.
Ahmed Tolba
2018년 5월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!