I figured it out and thought I would put my solution here incase anyone else has the same question.
FootStart_tRF
for i=1:numel(FootStart_tRF)
level=FootStart_tRF(i)
FootStart_xRF=FindTime(RFXS,Time, level)
end
Although this overwrites the FootStart_tRF variable with each loop.
Here's a version that puts all the values in one array (Retotal)
FootStart_tRF
for i=1:numel(FootStart_tRF)
level=FootStart_tRF(i)
FootStart_xRF=FindTime(RFXS,Time, level)
Total(i)=FootStart_xRF
Retotal=Total.'
end
function FootStart_xRF = FindTime(RFXS,Time,level)
cxi = find(diff(sign(Time-level)));
for k = 1:numel(cxi)
idxrng = max(1,cxi(k)-1) : min(numel(RFXS), cxi(k)+1);
FootStart_xRF(k) = interp1(Time(idxrng), RFXS(idxrng), level);
end
end