hi, according to an answer header = fread(ropaRadarReceive,bytesToRead);
where = find(header == 53);
if ~isempty(where)
%at least one 53 found
nextbytes = header(where + 1); %note that if more than one 53 is found, nextbytes will be a vector
%...
end
now I have found 53, that header can be followed by 0 or 1 or 2 or 3, OR normal bytes other than those values.
I want to test if the next byte of 53 is 0 or 1 or 2 or 3, if that's true, I want to get the bytes after 0 or 1 or 2 or 3. UNTILL the next header is found which is 53.
Please help me

답변 (2개)

Ameer Hamza
Ameer Hamza 2018년 5월 24일
편집: Ameer Hamza 2018년 5월 24일

1 개 추천

If more then one 53 are found then where will be a vector and you need to use it like this
nextbytes = header(where(1)+1:where(2)-1);

댓글 수: 7

Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
and how do I get the data after 53 is found and check if the next byte is 0, then get the data after 0 till the next 53 ? Thanks for your answer
Try this
if numel(where) > 1 & header(where(1)+1) == 0 % check if there are more then 1 53s and number after first 53 is 0.
nextbytes = header(where(1)+2:where(2)-1);
end
Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
편집: Ahmed Tolba 2018년 5월 24일
I need after byte 0 is found to get the data after it till the next 53
Ameer Hamza
Ameer Hamza 2018년 5월 24일
If you can give an example of your data, then it will be easier to suggest a solution.
Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
편집: Ahmed Tolba 2018년 5월 24일
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..etc
Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
I provided data
Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
I would like the next bytes after 0 and before the next 53

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

Andrei Bobrov
Andrei Bobrov 2018년 5월 24일
편집: Andrei Bobrov 2018년 5월 24일

1 개 추천

i1 = find(header(:)==53);
p = hankel(header(1:end-1),header(end-1:end));
i2 = find(ismember(p,[53*ones(4,1),(0:3)'],'rows'));
[~,aa] = setdiff(i1,i2);
i1 = i1(aa) + 1;
i2 = i2 + 2;
out = header(sort([i1(i1 < numel(header));i2(i2 < numel(header))]));
use
>> 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]
header =
Columns 1 through 18
53 0 1 2 3 4 5 6 7 8 9 53 1 24 59 5 95 95
Columns 19 through 26
53 2 59 58 575 75 53 0
>> i1 = find(header(:)==53);
p = hankel(header(1:end-1),header(end-1:end));
i2 = find(ismember(p,[53*ones(4,1),(0:3)'],'rows'));
[~,aa] = setdiff(i1,i2);
i2 = i2 + 2;
out = header(sort([i1(aa)+1;i2(i2 < numel(header))]))
out =
1 24 59
>>

댓글 수: 1

Ahmed Tolba
Ahmed Tolba 2018년 5월 24일
I would like the next bytes after 0 and before the next 53

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

카테고리

도움말 센터File Exchange에서 Get Started with 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