MATLAB: How to plot the sum of data with different lengths that have epoch time and recorded at different time instances

discrete time dataMATLABplotsummation

Greetings
I have 4 different discrete data recorded at the same time interval with different rates (they don't have same size, and might be recorded in different time seconds in between). I want to sum them to have the total value over time, where for example at a specific time instant I need the sum of all 4 values, even if the 4 vectors doesn't have values at the same exact time instant. [They start and end at the same time]. How can I do this in MATLAB?
The 4 vectors are plotted below, where what I am asking for is their sum:
Also, suppose now that I have this sum along with 2 other similar summations. Each vector now starts and ends in different times with different time steps. The first one ends before the second starts. Yet I want to compare their growth over time (plot them together), while x axis keep fixed time steps rather than tuples count, how to do it :)?
Thank you for your time to read this.

Best Answer

There can be many ways to do such an interpolation in MATLAB. A simple one is interp1(): https://www.mathworks.com/help/releases/R2020a/matlab/ref/interp1.html. retime() is also useful: https://www.mathworks.com/help/releases/R2020a/matlab/ref/timetable.retime.html, but first, you need to convert your data to the timetable. Attach the dataset for a more specific suggestion.