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!