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

1 次查看(过去 30 天)
Hi all,
I am having two matrices, the one is 50x2 and the other is 20x2. 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 50x2 matrix would be on the botom (i.e. the red), and the 20x2 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.

采纳的回答

Star Strider
Star Strider 2019-1-5
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).
  2 个评论
Konstantinos Tsitsilonis
Thanks for your useful input! A couple of hours later I managed to solve my problem using the functions you pointed out.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by