Ben, I'm not sure where you are starting from. I'm gonna show how to do this with timetables. Imagine you have a timetable containing data from three channels, sampled at 10Hz over 10 sec:
>> T = 10;
>> n = 100;
>> numChannels = 3;
>> X = cumsum(randn(n,numChannels));
>> tt = sortrows(array2timetable(X,"SampleRate",n/T));
tt =
8×3 timetable
Time X1 X2 X3
_______ ________ ________ _______
0 sec -0.33824 1.0395 0.94041
0.1 sec 0.19002 0.92269 1.2896
0.2 sec 1.2469 0.27439 3.1488
0.3 sec 1.2617 0.23641 4.0759
0.4 sec 2.8764 0.037084 2.849
0.5 sec 2.0606 0.91875 2.5217
0.6 sec 0.062812 0.86261 3.4134
0.7 sec -0.68538 0.021371 3.7015
[snip]
And imagine you have 8 events for those channels over that time range:
>> numEvents = 8;
>> events = timetable(seconds(sort(T*rand(numEvents,1))),randi(numChannels,numEvents,1),'VariableNames',"Channel")
events =
8×1 timetable
Time Channel
__________ _______
2.1327 sec 2
2.6871 sec 1
3.8015 sec 2
4.1693 sec 2
4.7535 sec 3
6.809 sec 2
7.7221 sec 3
9.8668 sec 2
The following code interpolates each channel at its event times and overlays that on a plot of the raw data:
for chnl = 1:numChannels
chnlEvents = retime(tt(:,chnl),events.Time(events.Channel == chnl),"linear");
subplot(3,1,chnl), plot(tt.Time,tt{:,chnl},'b-',chnlEvents.Time,chnlEvents{:,1},'r*','MarkerSize',10)
end
and results in a plot like this
The stackedplot function would be a fine way to plot the raw data on three axes, but that will not let you add the overlay. So the code above makes the three plots "by hand".