It is not trivial in the sense that REGEXP provides you with two series of data with no information for relating one to the other. I see two options (without thinking too much)..
1. Instead of calling REGEXP twice, you call it a first time to get blocks based on a split matching 'MSN_BER'. You can then loop over these blocks and extract data that are to be mapped. E.g. (not tested):
EDIT: splitting using REGEXP is simpler than my first proposal..
bufferSplit = regexp(buffer, 'MSN_BER', 'split') ;
for bId = 1 : length(bufferSplit)
if isempty(bufferSplit{bId}), continue ; end
end
this way you know that, at each step of the loop, BER_State_Data and AC12_Data belong to the same block.
First proposal (I leave it for the record):
startPos = regexp(buffer, 'MSN_BER', 'start') ;
nBlocks = length(startPos) ;
for bId = 1 : nBlocks
if bId < nBlocks
miniBuffer = buffer(startPos(bId):startPos(bId+1)-1) ;
else
miniBuffer = buffer(startPos(bId):end) ;
end
end
2. If you can count on the fact (?) that the 'Time Tag:' field associated with entries that belong to the same block as a given BER entry are <= the 'Rx'd at:' (or State Time) field of the BER entry, then you can build the join directly from what you already have, using the 2nd column of BER_State_Data and the first column of AC12_Data. E.g. (not tested):
for berId = 1 : size(BER_State_Data, 1)
if berId == 1, prev = 0 ; else prev = BER_State_Data(berId-1,2) ; end
ac12Ids = AC12_data(:,1)>prev & AC12_data(:,1)<=BER_State_Data(berId,2) ;
end
=========================================================
PS: if you are the Brad who asked earlier about calling various functions based on a "per column" function ID, here is one example:
f{1} = @sin ;
f{2} = @(x) x.^(1/2) ;
f{3} = @(x) -x ;
M = magic(8)
c = [1, 1, 1, 2, 2, 3, 3, 3] ;
fM = arrayfun(@(cId) f{c(cId)}(M(:,cId)), 1:length(c), 'UniformOutput', false);
cell2mat(fM)
Best Answer