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
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
Ahmed Tolba 2018년 5월 24일
just ignore it if the 53 is followed by something other 0,1,2
dpb
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
Ahmed Tolba 2018년 5월 24일
the protocal always start with 53 then its followed by 0 or 1 or 2 or 3, then it continues adding bytes after 53 1,2,3.. so its like header 53 and which ADC signal which is 0,1,2,3

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

 채택된 답변

Walter Roberson
Walter Roberson 2018년 5월 24일

1 개 추천

where = [find(header(1:end-1)==53 & ismember(header(2:end), [0 1 2 3])), length(header)+1];
lengths = diff(where);
bytesplits = mat2cell(header(where(1):end), 1, lengths);
bytesplits is now a cell array in which each entry is a vector starting with an appropriate header.

댓글 수: 3

Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
Thanks, how to get the bytesplits, like the first section from 53 0 xxxx 53 1 xxx
Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
I mean convert bytesplits into vectors so that I can plot them
for K = 1 : length(bytesplits)
plot(bytesplits{K}(3:end), 'DisplayName', sprintf('#%d', K));
hold on
end
hold off
legend('show');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2018년 5월 24일

댓글:

2018년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by