MATLAB: Plot matrices in area graph of unequal length (i.e. size of rows)

areaarraygraphlengthmatrixnanpermutereshapesize;

Hi all,
I am having two matrices, the one is 50×2 and the other is 20×2. The first columns of both are dates, and the second colums are payments per each date. I would simply like to display the data in an area graph where the 50×2 matrix would be on the botom (i.e. the red), and the 20×2 matrix would be on the top (i.e. the yellow). Obviously the sum of both vectors would be the total height of the graph.
However to peform such a task, as I perceive it, I would have to make the two vectors compatible dimensionwise (i.e. have the same number of rows).
My thinking is to try to 'reshape' the matrices such as any idetical numbers on the first colum become removed, and numbers of the second column that remain, are stacked as more colums, with the gaps filled by either zero on nan.
Here is an example, 'cause it can be hard to understand:
X_init = [7.3743 0.0383 ;
7.3743 0.0379;
7.3743 0.0377;
7.3743 0.0378;
7.3743 0.0374;
7.3743 0.0273;
7.3742 0.0272;
7.3742 0.0272;
7.3742 0.0270;
7.3742 0.0270] ; % Initial matrix
X_resh = [7.3743 0.0383 0.0379 0.0377 0.0378 0.0374 0.0273 ;
7.3742 0.0272 0.0270 0.0270 NaN NaN NaN] ; % Reshaped Matrix
Thus far I am not certain that the above might lead to the desired result.
Thanks for your help in advance
KR,
KMT.

Best Answer

The only approach I can suggest is to interpolate one or both data sets to a common set of dates. This is best done using the retime (link) function. This first requires that you create your data as a timetable (see the documentation section on Create Timetables (link) to understand how to do that).