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

조회 수: 2 (최근 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
Konstantinos Tsitsilonis 2019년 1월 5일
Thanks for your useful input! A couple of hours later I managed to solve my problem using the functions you pointed out.
Star Strider
Star Strider 2019년 1월 5일
As always, my pleasure!
The newer time functions are extremely useful.

댓글을 달려면 로그인하십시오.

추가 답변 (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