find data in array
显示 更早的评论
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
2018-5-24
编辑:Ameer Hamza
2018-5-24
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
2018-5-24
Ameer Hamza
2018-5-24
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
2018-5-24
编辑:Ahmed Tolba
2018-5-24
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
2018-5-24
编辑:Ahmed Tolba
2018-5-24
Ahmed Tolba
2018-5-24
Ahmed Tolba
2018-5-24
Andrei Bobrov
2018-5-24
编辑:Andrei Bobrov
2018-5-24
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
>>
类别
在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!