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

Réponses (2)

Ameer Hamza
Ameer Hamza le 24 Mai 2018
Modifié(e) : Ameer Hamza le 24 Mai 2018

1 vote

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 commentaires

Ahmed Tolba
Ahmed Tolba le 24 Mai 2018
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
Ameer Hamza
Ameer Hamza le 24 Mai 2018
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 le 24 Mai 2018
Modifié(e) : Ahmed Tolba le 24 Mai 2018
I need after byte 0 is found to get the data after it till the next 53
Ameer Hamza
Ameer Hamza le 24 Mai 2018
If you can give an example of your data, then it will be easier to suggest a solution.
Ahmed Tolba
Ahmed Tolba le 24 Mai 2018
Modifié(e) : Ahmed Tolba le 24 Mai 2018
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 le 24 Mai 2018
I provided data
Ahmed Tolba
Ahmed Tolba le 24 Mai 2018
I would like the next bytes after 0 and before the next 53

Connectez-vous pour commenter.

Andrei Bobrov
Andrei Bobrov le 24 Mai 2018
Modifié(e) : Andrei Bobrov le 24 Mai 2018

1 vote

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 commentaire

Ahmed Tolba
Ahmed Tolba le 24 Mai 2018
I would like the next bytes after 0 and before the next 53

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Tags

Commenté :

le 24 Mai 2018

Community Treasure Hunt

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

Start Hunting!

Translated by